Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/ArrayReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -104,7 +104,7 @@ public function mixedValue(string $aPath, $default = null)
{
$value = $this->getValueFromPath($aPath);

if (is_null($value)) {
if ($value === null) {
return $default;
}

Expand All @@ -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;
Expand All @@ -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);
}

/**
Expand All @@ -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;
Expand Down