File tree Expand file tree Collapse file tree 3 files changed +37
-9
lines changed Expand file tree Collapse file tree 3 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ $value = $data->getRequiredDateTime('key');
146146
147147> Throws always ` NotAnArrayException ` exception if value exists but is not an array.
148148
149- Get always an array event if provided data is missing or if null.
149+ Get always an array even if provided data is missing or if null.
150150
151151``` php
152152$value = $data->getArray('key');
@@ -155,7 +155,7 @@ $value = $data->getArray('key');
155155Get nullable array.
156156
157157``` php
158- $value = $data->getRequiredArray ('key');
158+ $value = $data->getNullableArray ('key');
159159```
160160
161161Get required array that is not empty. Throws ` ArrayIsEmptyException ` exception if missing.
@@ -168,12 +168,18 @@ $value = $data->getRequiredArray('key');
168168
169169> Throws always ` NotAnArrayException ` exception if value exists but is not an array.
170170
171- Try to get nullable array from data and wrap it in ` GetValue ` instance .
171+ Get always ` GetValue ` instance even if provided data is missing or if null .
172172
173173``` php
174174$value = $data->getArrayGetter('key');
175175```
176176
177+ Try to get nullable array from data and wrap it in ` GetValue ` instance.
178+
179+ ``` php
180+ $value = $data->getNullableArrayGetter('key');
181+ ```
182+
177183Try to get non-empty array from data and wrap it in ` GetValue ` instance. Throws ` ArrayIsEmptyException ` exception if
178184missing.
179185
Original file line number Diff line number Diff line change @@ -228,17 +228,25 @@ public function getRequiredArray(string $key): array
228228 }
229229
230230 /**
231- * Ensures that always an array getter will be returned (if missing in $data or if null) .
231+ * Get always `GetValue` instance even if provided data is missing or if null.
232232 */
233- public function getArrayGetter (string $ key ): ?self
233+ public function getArrayGetter (string $ key ): self
234+ {
235+ return new self (new ArrayData ($ this ->getArray ($ key )), $ this ->exceptionBuilder , $ this ->getValidatedValueAction );
236+ }
237+
238+ /**
239+ * Try to get nullable array from data and wrap it in `GetValue` instance.
240+ */
241+ public function getNullableArrayGetter (string $ key ): ?self
234242 {
235243 $ value = $ this ->getNullableArray ($ key );
236244
237245 if ($ value === null || $ value === []) {
238246 return null ;
239247 }
240248
241- return new self (new ArrayData ($ value ), $ this ->exceptionBuilder );
249+ return new self (new ArrayData ($ value ), $ this ->exceptionBuilder , $ this -> getValidatedValueAction );
242250 }
243251
244252 /**
@@ -248,7 +256,7 @@ public function getRequiredArrayGetter(string $key): self
248256 {
249257 $ value = $ this ->getRequiredArray ($ key );
250258
251- return new self (new ArrayData ($ value ), $ this ->exceptionBuilder );
259+ return new self (new ArrayData ($ value ), $ this ->exceptionBuilder , $ this -> getValidatedValueAction );
252260 }
253261
254262 /**
Original file line number Diff line number Diff line change @@ -56,12 +56,26 @@ public function testGetArrayGetterOnNonArray(): void
5656
5757 public function testGetArrayGetterOnNonExistingItem (): void
5858 {
59- $ this ->assertNull ($ this ->data ->getArrayGetter ('' ));
59+ $ result = $ this ->data ->getArrayGetter ('' );
60+ $ this ->assertInstanceOf (GetValue::class, $ result );
61+ $ this ->assertEmpty ($ result ->data ->get ());
6062 }
6163
6264 public function testGetArrayGetterOnEmptyArray (): void
6365 {
64- $ this ->assertNull ($ this ->data ->getArrayGetter (self ::KeyItemsEmpty));
66+ $ result = $ this ->data ->getArrayGetter (self ::KeyItemsEmpty);
67+ $ this ->assertInstanceOf (GetValue::class, $ result );
68+ $ this ->assertEmpty ($ result ->data ->get ());
69+ }
70+
71+ public function testGetNullableArrayGetterOnNonExistingItem (): void
72+ {
73+ $ this ->assertNull ($ this ->data ->getNullableArrayGetter ('' ));
74+ }
75+
76+ public function testGetNullableArrayGetterOnEmptyArray (): void
77+ {
78+ $ this ->assertNull ($ this ->data ->getNullableArrayGetter (self ::KeyItemsEmpty));
6579 }
6680
6781 protected function assertItem (
You can’t perform that action at this time.
0 commit comments