@@ -53,7 +53,7 @@ public function upsert(
5353 $ valueJson = $ this ->encodeValue ($ normalizedValue );
5454 $ visibility = $ currentVisibility ?? FieldExposurePolicy::from ($ definition ->getExposurePolicy ())->initialVisibility ()->value ;
5555 if (!FieldVisibility::isValid ($ visibility )) {
56- throw new InvalidArgumentException ($ this ->l10n ->t ('current_visibility is not supported ' ));
56+ throw new InvalidArgumentException ($ this ->l10n ->t ('The provided visibility value is not supported. ' ));
5757 }
5858
5959 $ entity = $ this ->fieldValueMapper ->findByFieldDefinitionIdAndUserUid ($ definition ->getId (), $ userUid ) ?? new FieldValue ();
@@ -145,16 +145,17 @@ public function searchByDefinition(
145145 int $ offset ,
146146 ): array {
147147 if ($ limit < 1 || $ limit > self ::SEARCH_MAX_LIMIT ) {
148+ // TRANSLATORS %d is the maximum supported search limit.
148149 throw new InvalidArgumentException ($ this ->l10n ->t ('limit must be between 1 and %d ' , [self ::SEARCH_MAX_LIMIT ]));
149150 }
150151
151152 if ($ offset < 0 ) {
152- throw new InvalidArgumentException ($ this ->l10n ->t ('offset must be greater than or equal to 0 ' ));
153+ throw new InvalidArgumentException ($ this ->l10n ->t ('The offset must be greater than or equal to 0. ' ));
153154 }
154155
155156 $ normalizedOperator = strtolower (trim ($ operator ));
156157 if (!in_array ($ normalizedOperator , [self ::SEARCH_OPERATOR_EQ , self ::SEARCH_OPERATOR_CONTAINS ], true )) {
157- throw new InvalidArgumentException ($ this ->l10n ->t ('search operator is not supported ' ));
158+ throw new InvalidArgumentException ($ this ->l10n ->t ('The search operator is not supported. ' ));
158159 }
159160
160161 $ searchValue = $ this ->normalizeSearchValue ($ definition , $ normalizedOperator , $ rawValue );
@@ -177,12 +178,12 @@ public function searchByDefinition(
177178
178179 public function updateVisibility (FieldDefinition $ definition , string $ userUid , string $ updatedByUid , string $ currentVisibility ): FieldValue {
179180 if (!FieldVisibility::isValid ($ currentVisibility )) {
180- throw new InvalidArgumentException ($ this ->l10n ->t ('current_visibility is not supported ' ));
181+ throw new InvalidArgumentException ($ this ->l10n ->t ('The provided visibility value is not supported. ' ));
181182 }
182183
183184 $ entity = $ this ->fieldValueMapper ->findByFieldDefinitionIdAndUserUid ($ definition ->getId (), $ userUid );
184185 if ($ entity === null ) {
185- throw new InvalidArgumentException ($ this ->l10n ->t ('field value not found ' ));
186+ throw new InvalidArgumentException ($ this ->l10n ->t ('No profile field value was found. ' ));
186187 }
187188
188189 $ previousValue = $ this ->extractScalarValue ($ entity ->getValueJson ());
@@ -229,7 +230,7 @@ public function serializeForResponse(FieldValue $value): array {
229230 */
230231 private function normalizeTextValue (array |string |int |float |bool $ rawValue ): array {
231232 if (is_array ($ rawValue )) {
232- throw new InvalidArgumentException ($ this ->l10n ->t ('text fields expect a scalar value ' ));
233+ throw new InvalidArgumentException ($ this ->l10n ->t ('Text fields require a single text value. ' ));
233234 }
234235
235236 return ['value ' => trim ((string )$ rawValue )];
@@ -241,12 +242,13 @@ private function normalizeTextValue(array|string|int|float|bool $rawValue): arra
241242 */
242243 private function normalizeSelectValue (array |string |int |float |bool $ rawValue , FieldDefinition $ definition ): array {
243244 if (!is_string ($ rawValue )) {
244- throw new InvalidArgumentException ($ this ->l10n ->t ('select fields expect a string value ' ));
245+ throw new InvalidArgumentException ($ this ->l10n ->t ('Select fields require one of the configured option values. ' ));
245246 }
246247
247248 $ value = trim ($ rawValue );
248249 $ options = json_decode ($ definition ->getOptions () ?? '[] ' , true );
249250 if (!in_array ($ value , $ options , true )) {
251+ // TRANSLATORS %s is an invalid option value provided by the user.
250252 throw new InvalidArgumentException ($ this ->l10n ->t ('"%s" is not a valid option for this field ' , [$ value ]));
251253 }
252254
@@ -259,7 +261,7 @@ private function normalizeSelectValue(array|string|int|float|bool $rawValue, Fie
259261 */
260262 private function normalizeNumberValue (array |string |int |float |bool $ rawValue ): array {
261263 if (is_array ($ rawValue ) || is_bool ($ rawValue ) || !is_numeric ($ rawValue )) {
262- throw new InvalidArgumentException ($ this ->l10n ->t ('number fields expect a numeric value ' ));
264+ throw new InvalidArgumentException ($ this ->l10n ->t ('Number fields require a numeric value. ' ));
263265 }
264266
265267 return ['value ' => str_contains ((string )$ rawValue , '. ' ) ? (float )$ rawValue : (int )$ rawValue ];
@@ -272,7 +274,7 @@ private function encodeValue(array $value): string {
272274 try {
273275 return json_encode ($ value , JSON_THROW_ON_ERROR );
274276 } catch (JsonException $ exception ) {
275- throw new InvalidArgumentException ($ this ->l10n ->t ('value_json could not be encoded ' ), 0 , $ exception );
277+ throw new InvalidArgumentException ($ this ->l10n ->t ('The stored value payload could not be encoded as JSON. ' ), 0 , $ exception );
276278 }
277279 }
278280
@@ -283,11 +285,11 @@ private function decodeValue(string $valueJson): array {
283285 try {
284286 $ decoded = json_decode ($ valueJson , true , 512 , JSON_THROW_ON_ERROR );
285287 } catch (JsonException $ exception ) {
286- throw new InvalidArgumentException ($ this ->l10n ->t ('value_json could not be decoded ' ), 0 , $ exception );
288+ throw new InvalidArgumentException ($ this ->l10n ->t ('The stored value payload could not be decoded from JSON. ' ), 0 , $ exception );
287289 }
288290
289291 if (!is_array ($ decoded )) {
290- throw new InvalidArgumentException ($ this ->l10n ->t ('value_json must decode to an object payload ' ));
292+ throw new InvalidArgumentException ($ this ->l10n ->t ('The stored value payload must decode to a JSON object. ' ));
291293 }
292294
293295 return $ decoded ;
@@ -328,13 +330,13 @@ private function normalizeSearchValue(FieldDefinition $definition, string $opera
328330 }
329331
330332 if (FieldType::from ($ definition ->getType ()) !== FieldType::TEXT ) {
331- throw new InvalidArgumentException ($ this ->l10n ->t ('contains operator is only supported for text fields ' ));
333+ throw new InvalidArgumentException ($ this ->l10n ->t ('The " contains" operator is only available for text fields. ' ));
332334 }
333335
334336 $ normalized = $ this ->normalizeValue ($ definition , $ rawValue );
335337 $ value = $ normalized ['value ' ] ?? null ;
336338 if (!is_string ($ value ) || $ value === '' ) {
337- throw new InvalidArgumentException ($ this ->l10n ->t ('contains operator requires a non-empty text value ' ));
339+ throw new InvalidArgumentException ($ this ->l10n ->t ('The " contains" operator requires a non-empty text value. ' ));
338340 }
339341
340342 return ['value ' => $ value ];
0 commit comments