From 3eb58f14357402f1ef897444da90aff1bba29c3f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 16 Oct 2024 20:56:35 +0800 Subject: [PATCH] [11.x] Improves PHP 8.4 compatibility (#53182) * [11.x] Improves PHP 8.4 compatibility Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * Apply fixes from StyleCI --------- Signed-off-by: Mior Muhammad Zaki Co-authored-by: StyleCI Bot --- .styleci.yml | 2 ++ .../Relations/Concerns/SupportsInverseRelations.php | 4 ++-- src/Illuminate/Foundation/Application.php | 2 +- src/Illuminate/Foundation/Console/ExceptionMakeCommand.php | 2 +- src/Illuminate/Queue/Console/WorkCommand.php | 4 ++-- src/Illuminate/Support/Onceable.php | 2 +- src/Illuminate/Support/ValidatedInput.php | 6 +++--- types/Support/Helpers.php | 4 ++-- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 05af66632431..079b642b8987 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,6 +1,8 @@ php: preset: laravel version: 8.2 + enabled: + - nullable_type_declarations finder: not-name: - bad-syntax-strategy.php diff --git a/src/Illuminate/Database/Eloquent/Relations/Concerns/SupportsInverseRelations.php b/src/Illuminate/Database/Eloquent/Relations/Concerns/SupportsInverseRelations.php index 6fd76ec0cae4..c7140d0a31e0 100644 --- a/src/Illuminate/Database/Eloquent/Relations/Concerns/SupportsInverseRelations.php +++ b/src/Illuminate/Database/Eloquent/Relations/Concerns/SupportsInverseRelations.php @@ -14,7 +14,7 @@ trait SupportsInverseRelations * * @var string|null */ - protected string|null $inverseRelationship = null; + protected ?string $inverseRelationship = null; /** * Instruct Eloquent to link the related models back to the parent after the relationship query has run. @@ -61,7 +61,7 @@ public function chaperone(?string $relation = null) * * @return string|null */ - protected function guessInverseRelation(): string|null + protected function guessInverseRelation(): ?string { return Arr::first( $this->getPossibleInverseRelations(), diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 7b9fdc8f5a62..c4c5f34bd42e 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1426,7 +1426,7 @@ public function terminate() /** * Get the service providers that have been loaded. * - * @return array + * @return array */ public function getLoadedProviders() { diff --git a/src/Illuminate/Foundation/Console/ExceptionMakeCommand.php b/src/Illuminate/Foundation/Console/ExceptionMakeCommand.php index bcd82ab0c57d..a38b11c711e8 100644 --- a/src/Illuminate/Foundation/Console/ExceptionMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ExceptionMakeCommand.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use function Laravel\Prompts\{confirm}; +use function Laravel\Prompts\confirm; #[AsCommand(name: 'make:exception')] class ExceptionMakeCommand extends GeneratorCommand diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index 7785ec3cb615..e36e352904b9 100644 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -199,7 +199,7 @@ protected function listenForEvents() * @param Throwable|null $exception * @return void */ - protected function writeOutput(Job $job, $status, Throwable $exception = null) + protected function writeOutput(Job $job, $status, ?Throwable $exception = null) { $this->outputUsingJson() ? $this->writeOutputAsJson($job, $status, $exception) @@ -260,7 +260,7 @@ protected function writeOutputForCli(Job $job, $status) * @param Throwable|null $exception * @return void */ - protected function writeOutputAsJson(Job $job, $status, Throwable $exception = null) + protected function writeOutputAsJson(Job $job, $status, ?Throwable $exception = null) { $log = array_filter([ 'level' => $status === 'starting' || $status === 'success' ? 'info' : 'warning', diff --git a/src/Illuminate/Support/Onceable.php b/src/Illuminate/Support/Onceable.php index 169a2b71470f..9a405da41198 100644 --- a/src/Illuminate/Support/Onceable.php +++ b/src/Illuminate/Support/Onceable.php @@ -17,7 +17,7 @@ class Onceable */ public function __construct( public string $hash, - public object|null $object, + public ?object $object, public $callable ) { // diff --git a/src/Illuminate/Support/ValidatedInput.php b/src/Illuminate/Support/ValidatedInput.php index 05d962681287..d272d7710e9f 100644 --- a/src/Illuminate/Support/ValidatedInput.php +++ b/src/Illuminate/Support/ValidatedInput.php @@ -93,7 +93,7 @@ public function missing($keys) * @param callable|null $default * @return $this|mixed */ - public function whenMissing($key, callable $callback, callable $default = null) + public function whenMissing($key, callable $callback, ?callable $default = null) { if ($this->missing($key)) { return $callback(data_get($this->all(), $key)) ?: $this; @@ -212,7 +212,7 @@ public function all() * @param callable|null $default * @return $this|mixed */ - public function whenHas($key, callable $callback, callable $default = null) + public function whenHas($key, callable $callback, ?callable $default = null) { if ($this->has($key)) { return $callback(data_get($this->all(), $key)) ?: $this; @@ -290,7 +290,7 @@ public function anyFilled($keys) * @param callable|null $default * @return $this|mixed */ - public function whenFilled($key, callable $callback, callable $default = null) + public function whenFilled($key, callable $callback, ?callable $default = null) { if ($this->filled($key)) { return $callback(data_get($this->all(), $key)) ?: $this; diff --git a/types/Support/Helpers.php b/types/Support/Helpers.php index 30f0f44c5b7c..ad3ff56aa1fe 100644 --- a/types/Support/Helpers.php +++ b/types/Support/Helpers.php @@ -41,7 +41,7 @@ })); assertType('Illuminate\Support\HigherOrderTapProxy', tap(new User())); -function testThrowIf(float|int $foo, DateTime $bar = null): void +function testThrowIf(float|int $foo, ?DateTime $bar = null): void { assertType('never', throw_if(true, Exception::class)); assertType('bool', throw_if(false, Exception::class)); @@ -59,7 +59,7 @@ function testThrowIf(float|int $foo, DateTime $bar = null): void assertType('never', throw_if('foo', Exception::class)); } -function testThrowUnless(float|int $foo, DateTime $bar = null): void +function testThrowUnless(float|int $foo, ?DateTime $bar = null): void { assertType('bool', throw_unless(true, Exception::class)); assertType('never', throw_unless(false, Exception::class));