diff --git a/src/ArrayReader.php b/src/ArrayReader.php index f8f4c5d..e17e544 100644 --- a/src/ArrayReader.php +++ b/src/ArrayReader.php @@ -36,30 +36,30 @@ public function integerValue(string $aPath, int $default = 0): int { $value = $this->getValueFromPath($aPath); - if (is_null($value)) { - return \intval($default); + if ($value === null) { + return $default; } - return \intval($value); + return (int)$value; } public function floatValue(string $aPath, float $default = 0.0): float { $value = $this->getValueFromPath($aPath); - if (is_null($value)) { - return \floatval($default); + if ($value === null) { + return $default; } - return \floatval($value); + return (float)$value; } public function booleanValue(string $aPath, bool $default = false): bool { $value = $this->getValueFromPath($aPath); - if (is_null($value)) { - return (bool)$default; + if ($value === null) { + return $default; } return (bool)$value; @@ -69,23 +69,23 @@ public function stringValue(string $aPath, string $default = ''): string { $value = $this->getValueFromPath($aPath); - if (is_null($value)) { - return \strval($default); + if ($value === null) { + return $default; } - return \strval($value); + return (string)$value; } public function arrayValue(string $aPath, array $default = []): array { $value = $this->getValueFromPath($aPath); - if (is_null($value)) { + if ($value === null) { return $default; } if (is_scalar($value)) { - return array($value); + return [$value]; } if (is_object($value)) { @@ -104,7 +104,7 @@ public function mixedValue(string $aPath, $default = null) { $value = $this->getValueFromPath($aPath); - if (is_null($value)) { + if ($value === null) { return $default; } @@ -117,7 +117,7 @@ public function pathExists(string $aPath): bool $arrayCopyOrValue = $this->originalArray; - foreach($pathKeys as $pathKey) { + foreach ($pathKeys as $pathKey) { if (!array_key_exists($pathKey, $arrayCopyOrValue)) { return false; @@ -139,7 +139,9 @@ protected function toPathKeys(string $aPath): array $aPath = str_replace('\.', '___IamADot___', $aPath); $parts = explode('.', $aPath); - return array_map(function ($part) { return str_replace('___IamADot___', '.', $part); }, $parts); + return array_map(function ($part) { + return str_replace('___IamADot___', '.', $part); + }, $parts); } /** @@ -152,7 +154,7 @@ protected function getValueFromPath(string $aPath) $arrayCopyOrValue = $this->originalArray; - foreach($pathKeys as $pathKey) { + foreach ($pathKeys as $pathKey) { if (!isset($arrayCopyOrValue[$pathKey])) { return null;