From c4fc504d5ffc610d04888d67dcecc99199dbfdd5 Mon Sep 17 00:00:00 2001 From: eriklukiman Date: Fri, 6 Dec 2024 00:40:36 +0700 Subject: [PATCH] handle default null for method parameters --- src/Attribute.php | 2 +- src/ErrorBag.php | 2 +- src/Helper.php | 6 +++--- src/Rules/Url.php | 2 +- tests/ValidatorTest.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Attribute.php b/src/Attribute.php index ebd7a11..c212867 100644 --- a/src/Attribute.php +++ b/src/Attribute.php @@ -211,7 +211,7 @@ public function getKeyIndexes(): array * @param string|null $key * @return mixed */ - public function getValue(string $key = null) + public function getValue(string|null $key = null) { if ($key && $this->isArrayAttribute()) { $key = $this->resolveSiblingKey($key); diff --git a/src/ErrorBag.php b/src/ErrorBag.php index 2836d4a..51bbd3b 100644 --- a/src/ErrorBag.php +++ b/src/ErrorBag.php @@ -209,7 +209,7 @@ protected function isWildcardKey(string $key): bool * @param mixed $ruleName * @return array */ - protected function filterMessagesForWildcardKey(string $key, $ruleName = null): array + protected function filterMessagesForWildcardKey(string $key, mixed $ruleName = null): array { $messages = $this->messages; $pattern = preg_quote($key, '#'); diff --git a/src/Helper.php b/src/Helper.php index 06e0ada..392d775 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -63,7 +63,7 @@ public static function arrayHas(array $array, string $key): bool * @param mixed $default * @return mixed */ - public static function arrayGet(array $array, $key, $default = null) + public static function arrayGet(array $array, string|null $key, mixed $default = null) : mixed { if (is_null($key)) { return $array; @@ -219,7 +219,7 @@ public static function snakeCase(string $value, string $delimiter = '_'): string * @param string|null $lastSeparator * @return string */ - public static function join(array $pieces, string $separator, string $lastSeparator = null): string + public static function join(array $pieces, string $separator, string|null $lastSeparator = null): string { if (is_null($lastSeparator)) { $lastSeparator = $separator; @@ -245,7 +245,7 @@ public static function join(array $pieces, string $separator, string $lastSepara * @param string|null $suffix * @return array */ - public static function wraps(array $strings, string $prefix, string $suffix = null): array + public static function wraps(array $strings, string $prefix, string|null $suffix = null): array { if (is_null($suffix)) { $suffix = $prefix; diff --git a/src/Rules/Url.php b/src/Rules/Url.php index 3ed8583..bb48f3c 100644 --- a/src/Rules/Url.php +++ b/src/Rules/Url.php @@ -82,7 +82,7 @@ public function validateBasic($value): bool * @param null $scheme * @return bool */ - public function validateCommonScheme($value, $scheme = null): bool + public function validateCommonScheme($value, mixed $scheme = null): bool { if (!$scheme) { return $this->validateBasic($value) && (bool) preg_match("/^\w+:\/\//i", $value); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index a17a123..09e0946 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -835,7 +835,7 @@ public function testEmptyArrayAssocValidation() * * @dataProvider rootAsteriskProvider */ - public function testRootAsteriskValidation(array $data, array $rules, $errors = null) + public function testRootAsteriskValidation(array $data, array $rules, mixed $errors = null) { $validation = $this->validator->validate($data, $rules); $this->assertSame(empty($errors), $validation->passes());