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
20 changes: 20 additions & 0 deletions src/Traits/TypeableBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public function getInt(int|string $key, ?int $defaultValue = null, string $charN
return $defaultValue;
}

/**
* Return a forced integer value from the get() method
* @param int|string $key the field key, can be nested for example "0.author.id"
* @param int $defaultValue the default integer value returned if no value is found
* @param non-empty-string $charNestedKey for nested field the . character is the default
*/
public function getIntStrict(int|string $key, int $defaultValue = 0, string $charNestedKey = "."): int
{
$returnValue = $this->get($key, $defaultValue, $charNestedKey);

if ($returnValue === null) {
return $defaultValue;
}

if (is_scalar($returnValue)) {
return intval($returnValue);
}

return $defaultValue;
}
/**
* Return a forced boolean value from the get() method
* @param int|string $key the filed key , can be nested for example "commits.0.editable"
Expand Down