Skip to content

Commit

Permalink
Add parameter and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Nov 27, 2022
1 parent 2698c32 commit 74de5ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
9 changes: 3 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ parameters:
level: 8
paths:
- src
- tests
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#Cannot cast mixed to int.#'
- '#Cannot cast mixed to string.#'
- '#Cannot cast mixed to float.#'
- '#Parameter \#1 \$time of class Cake\\Chronos\\Chronos constructor expects DateTimeInterface\|int\|string\|null, mixed given.#'
- '#Cannot access offset string on mixed.#'
- '#Property (.*?) type has no value type specified in iterable type array#'
- '#Method (.*?) has parameter (.*?) with no value type specified in iterable type array#'
- '#Method (.*?) return type has no value type specified in iterable type array#'
44 changes: 22 additions & 22 deletions src/ArrayReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
final class ArrayReader
{
/**
* @var array<mixed> The data
* @var array
*/
private $data;
private array $data;

/**
* The constructor.
*
* @param array<mixed> $data Data
* @param array $data Data
*/
public function __construct(array $data = [])
{
Expand All @@ -28,7 +28,7 @@ public function __construct(array $data = [])
/**
* Crate instance from array.
*
* @param array<mixed> $data The data
* @param array $data The data
*
* @return self The new instance
*/
Expand Down Expand Up @@ -66,7 +66,7 @@ public function getInt(string $key, int $default = null): int
*
* @return int|null The value
*/
public function findInt(string $key, int $default = null)
public function findInt(string $key, int $default = null): ?int
{
$value = $this->find($key, $default);

Expand Down Expand Up @@ -102,11 +102,11 @@ public function getString(string $key, string $default = null): string
* Get value as string or null.
*
* @param string $key The key
* @param string $default The default value
* @param string|null $default The default value
*
* @return string|null The value
*/
public function findString(string $key, string $default = null)
public function findString(string $key, string $default = null): ?string
{
$value = $this->find($key, $default);

Expand All @@ -121,11 +121,11 @@ public function findString(string $key, string $default = null)
* Get value as array.
*
* @param string $key The key
* @param array<mixed>|null $default The default value
* @param array|null $default The default value
*
* @throws InvalidArgumentException
*
* @return array<mixed> The value
* @return array The value
*/
public function getArray(string $key, array $default = null): array
{
Expand All @@ -142,11 +142,11 @@ public function getArray(string $key, array $default = null): array
* Get value as array or null.
*
* @param string $key The key
* @param array<mixed> $default The default value
* @param array|null $default The default value
*
* @return array<mixed>|null The value
* @return array|null The value
*/
public function findArray(string $key, array $default = null)
public function findArray(string $key, array $default = null): ?array
{
$value = $this->find($key, $default);

Expand Down Expand Up @@ -182,11 +182,11 @@ public function getFloat(string $key, float $default = null): float
* Get value as float or null.
*
* @param string $key The key
* @param float $default The default value
* @param float|null $default The default value
*
* @return float|null The value
*/
public function findFloat(string $key, float $default = null)
public function findFloat(string $key, float $default = null): ?float
{
$value = $this->find($key, $default);

Expand Down Expand Up @@ -226,7 +226,7 @@ public function getBool(string $key, bool $default = null): bool
*
* @return bool|null The value
*/
public function findBool(string $key, bool $default = null)
public function findBool(string $key, bool $default = null): ?bool
{
$value = $this->find($key, $default);

Expand Down Expand Up @@ -266,11 +266,11 @@ public function getChronos(string $key, Chronos $default = null): Chronos
* Get value as Chronos or null.
*
* @param string $key The key
* @param Chronos $default The default value
* @param Chronos|null $default The default value
*
* @return Chronos|null The value
*/
public function findChronos(string $key, Chronos $default = null)
public function findChronos(string $key, Chronos $default = null): ?Chronos
{
$value = $this->find($key, $default);

Expand All @@ -293,13 +293,13 @@ public function findChronos(string $key, Chronos $default = null)
*
* @return mixed|null The value
*/
public function find(string $path, $default = null)
public function find(string $path, mixed $default = null): mixed
{
if (array_key_exists($path, $this->data)) {
return $this->data[$path] ?? $default;
}

if (strpos($path, '.') === false) {
if (!str_contains($path, '.')) {
return $default;
}

Expand All @@ -320,15 +320,15 @@ public function find(string $path, $default = null)
/**
* Return all data as array.
*
* @return array<mixed> The data
* @return array The data
*/
public function all(): array
{
return $this->data;
}

/**
* Test whether or not a given path exists in $data.
* Test whether a given path exists in $data.
* This method uses the same path syntax as Hash::extract().
*
* Checking for paths that could target more than one element will
Expand Down Expand Up @@ -373,7 +373,7 @@ public function isEmpty(string $path): bool
*
* @return bool The status
*/
private function isNullOrBlank($value): bool
private function isNullOrBlank(mixed $value): bool
{
return $value === null || $value === '';
}
Expand Down

0 comments on commit 74de5ed

Please sign in to comment.