@@ -40,7 +40,7 @@ public function getInt(string $key, int $default = null): int
4040 {
4141 $ value = $ this ->find ($ key , $ default );
4242
43- if ($ value === null ) {
43+ if ($ this -> isNullOrBlank ( $ value) ) {
4444 throw new InvalidArgumentException (sprintf ('No value found for key "%s" ' , $ key ));
4545 }
4646
@@ -57,13 +57,13 @@ public function getInt(string $key, int $default = null): int
5757 */
5858 public function findInt (string $ key , int $ default = null )
5959 {
60- $ result = $ this ->find ($ key , $ default );
60+ $ value = $ this ->find ($ key , $ default );
6161
62- if ($ result === null ) {
62+ if ($ this -> isNullOrBlank ( $ value ) ) {
6363 return null ;
6464 }
6565
66- return (int )$ result ;
66+ return (int )$ value ;
6767 }
6868
6969 /**
@@ -120,7 +120,7 @@ public function getArray(string $key, array $default = null): array
120120 {
121121 $ value = $ this ->find ($ key , $ default );
122122
123- if ($ value === null ) {
123+ if ($ this -> isNullOrBlank ( $ value) ) {
124124 throw new InvalidArgumentException (sprintf ('No value found for key "%s" ' , $ key ));
125125 }
126126
@@ -139,7 +139,7 @@ public function findArray(string $key, array $default = null)
139139 {
140140 $ value = $ this ->find ($ key , $ default );
141141
142- if ($ value === null ) {
142+ if ($ this -> isNullOrBlank ( $ value) ) {
143143 return null ;
144144 }
145145
@@ -160,7 +160,7 @@ public function getFloat(string $key, float $default = null): float
160160 {
161161 $ value = $ this ->find ($ key , $ default );
162162
163- if ($ value === null ) {
163+ if ($ this -> isNullOrBlank ( $ value) ) {
164164 throw new InvalidArgumentException (sprintf ('No value found for key "%s" ' , $ key ));
165165 }
166166
@@ -179,7 +179,7 @@ public function findFloat(string $key, float $default = null)
179179 {
180180 $ value = $ this ->find ($ key , $ default );
181181
182- if ($ value === null ) {
182+ if ($ this -> isNullOrBlank ( $ value) ) {
183183 return null ;
184184 }
185185
@@ -200,7 +200,7 @@ public function getBool(string $key, bool $default = null): bool
200200 {
201201 $ value = $ this ->find ($ key , $ default );
202202
203- if ($ value === null ) {
203+ if ($ this -> isNullOrBlank ( $ value) ) {
204204 throw new InvalidArgumentException (sprintf ('No value found for key "%s" ' , $ key ));
205205 }
206206
@@ -219,7 +219,7 @@ public function findBool(string $key, bool $default = null)
219219 {
220220 $ value = $ this ->find ($ key , $ default );
221221
222- if ($ value === null ) {
222+ if ($ this -> isNullOrBlank ( $ value) ) {
223223 return null ;
224224 }
225225
@@ -240,7 +240,7 @@ public function getChronos(string $key, Chronos $default = null): Chronos
240240 {
241241 $ value = $ this ->find ($ key , $ default );
242242
243- if ($ value === null ) {
243+ if ($ this -> isNullOrBlank ( $ value) ) {
244244 throw new InvalidArgumentException (sprintf ('No value found for key "%s" ' , $ key ));
245245 }
246246
@@ -265,7 +265,11 @@ public function findChronos(string $key, Chronos $default = null)
265265 {
266266 $ value = $ this ->find ($ key , $ default );
267267
268- if ($ value === null || $ value instanceof Chronos) {
268+ if ($ this ->isNullOrBlank ($ value )) {
269+ return null ;
270+ }
271+
272+ if ($ value instanceof Chronos) {
269273 return $ value ;
270274 }
271275
@@ -344,4 +348,16 @@ public function isEmpty(string $path): bool
344348 {
345349 return empty ($ this ->find ($ path ));
346350 }
351+
352+ /**
353+ * Is null or blank.
354+ *
355+ * @param mixed $value The value
356+ *
357+ * @return bool The status
358+ */
359+ private function isNullOrBlank ($ value ): bool
360+ {
361+ return $ value === null || $ value === '' ;
362+ }
347363}
0 commit comments