Skip to content

Commit

Permalink
Fixes for PHP 8.4 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-redfern committed Nov 27, 2024
1 parent 241ecb9 commit b168cc9
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

2024-11-27
----------

* fix deprecation notices for PHP 8.4

2024-08-01
----------

Expand Down Expand Up @@ -31,7 +36,7 @@ Change Log
2024-03-02
----------

* required PHP 8.1+
* require PHP 8.1+
* update dependencies
* fix missing return types

Expand Down
4 changes: 2 additions & 2 deletions src/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Attribute
public function __construct(
Validation $validation,
string $key,
string $alias = null,
?string $alias = null,
array $rules = []
) {
$this->validation = $validation;
Expand Down Expand Up @@ -115,7 +115,7 @@ public function validation(): Validation
return $this->validation;
}

public function value(string $key = null): mixed
public function value(?string $key = null): mixed
{
if ($key && $this->isArrayAttribute()) {
$key = $this->resolveSiblingKey($key);
Expand Down
2 changes: 1 addition & 1 deletion src/ErrorBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function isWildcardKey(string $key): bool
return str_contains($key, '*');
}

private function filterMessagesForWildcardKey(string $key, $ruleName = null): array
private function filterMessagesForWildcardKey(string $key, ?string $ruleName = null): array
{
$messages = $this->errors;
$pattern = preg_quote($key, '#');
Expand Down
2 changes: 1 addition & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function registerDefaultMessages(): void
* @return void
* @throws MessageException
*/
public function registerLanguageMessages(string $lang, string $file = null): void
public function registerLanguageMessages(string $lang, ?string $file = null): void
{
$file ??= sprintf('%s/Resources/i18n/%s.php', __DIR__, preg_replace('/[^A-Za-z0-9\-]/', '', $lang));

Expand Down
4 changes: 2 additions & 2 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static function flattenValues(array $values): string
*
* @return string
*/
public static function join(array $pieces, string $separator, string $lastSeparator = null): string
public static function join(array $pieces, string $separator, ?string $lastSeparator = null): string
{
if (is_null($lastSeparator)) {
$lastSeparator = $separator;
Expand All @@ -227,7 +227,7 @@ public static function join(array $pieces, string $separator, string $lastSepara
*
* @return array
*/
public static function wraps(array $strings, string $prefix, string $suffix = null): array
public static function wraps(array $strings, string $prefix, ?string $suffix = null): array
{
if (is_null($suffix)) {
$suffix = $prefix;
Expand Down
8 changes: 4 additions & 4 deletions src/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function replace(string $lang, string $key, string $message): self
return $this;
}

public function firstOf(array $keys, string $lang = null): string
public function firstOf(array $keys, ?string $lang = null): string
{
foreach ($keys as $key) {
if ($this->has($key, $lang)) {
Expand All @@ -52,17 +52,17 @@ public function firstOf(array $keys, string $lang = null): string
throw MessageException::noMessageForKeys($lang ?? $this->defaultLang, $keys);
}

public function get(string $key, string $lang = null): ?string
public function get(string $key, ?string $lang = null): ?string
{
return $this->messages[$lang ?? $this->defaultLang][$key] ?? null;
}

public function has(string $key, string $lang = null): bool
public function has(string $key, ?string $lang = null): bool
{
return isset($this->messages[$lang ?? $this->defaultLang][$key]);
}

public function hasAnyOf(array $keys, string $lang = null): bool
public function hasAnyOf(array $keys, ?string $lang = null): bool
{
foreach ($keys as $key) {
if ($this->has($key, $lang)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Mimes extends Rule
protected string $message = 'rule.mimes';
protected MimeTypeGuesserContract $guesser;

public function __construct(MimeTypeGuesserContract $guesser = null)
public function __construct(?MimeTypeGuesserContract $guesser = null)
{
$this->guesser = $guesser ?? new MimeTypeGuesser();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Unique.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function column(string $column): self
return $this;
}

public function ignore(mixed $value, string $column = null): self
public function ignore(mixed $value, ?string $column = null): self
{
$this->params['ignore'] = $value;
$this->params['ignore_column'] = $column;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UploadedFile extends Rule implements BeforeValidate
protected string $message = 'rule.uploaded_file';
protected MimeTypeGuesserContract $guesser;

public function __construct(MimeTypeGuesserContract $guesser = null)
public function __construct(?MimeTypeGuesserContract $guesser = null)
{
$this->guesser = $guesser ?? new MimeTypeGuesser();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function check(mixed $value): bool
/**
* Validate $value has a scheme or has the specified scheme
*/
private function validateCommonScheme(string $value, string $scheme = null): bool
private function validateCommonScheme(string $value, ?string $scheme = null): bool
{
if ($scheme) {
return $this->validateBasic($value) && preg_match("/^$scheme:\/\//", $value);
Expand Down
2 changes: 1 addition & 1 deletion src/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function parseRule(string $rule): array
if (in_array($ruleName, ['matches', 'regex'])) {
$params = [$exp[1]];
} else {
$params = isset($exp[1]) ? str_getcsv($exp[1]) : [];
$params = isset($exp[1]) ? str_getcsv($exp[1], escape: '\\') : [];
}

return [$ruleName, $params];
Expand Down

0 comments on commit b168cc9

Please sign in to comment.