From f9b92418fce75523645d22d82338e0acb7519b55 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Mon, 23 Jan 2023 12:56:13 +0800 Subject: [PATCH] Fix PHPStan issues again, change fire to dispatch on all events --- phpstan-baseline.neon | 13 +++++++++---- src/Database/Connections/Connection.php | 2 +- src/Database/DatabaseServiceProvider.php | 2 +- src/Foundation/Application.php | 6 +++--- src/Foundation/Console/ClearCompiledCommand.php | 3 +++ src/Foundation/Console/Kernel.php | 2 +- src/Mail/MailManager.php | 4 ++-- src/Router/CoreRouter.php | 4 ++-- src/Support/Facades/Schema.php | 2 +- tests/Events/DispatcherTest.php | 4 ++-- tests/Support/EventFakeTest.php | 2 +- 11 files changed, 26 insertions(+), 18 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0ccd4ae8a..8336286cb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -756,14 +756,14 @@ parameters: path: src/Extension/Extendable.php - - message: "#^Call to an undefined method Illuminate\\\\Events\\\\Dispatcher\\:\\:fire\\(\\)\\.$#" - count: 2 + message: "#^Parameter \\#3 \\$replacement of method Illuminate\\\\Support\\\\Collection\\,Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), mixed\\>\\>\\:\\:splice\\(\\) expects array\\\\>, array\\{array\\} given\\.$#" + count: 1 path: src/Foundation/Application.php - - message: "#^Parameter \\#3 \\$replacement of method Illuminate\\\\Support\\\\Collection\\,Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), mixed\\>\\>\\:\\:splice\\(\\) expects array\\\\>, array\\{array\\} given\\.$#" + message: "#^Strict comparison using \\=\\=\\= between array\\|null and false will always evaluate to false\\.$#" count: 1 - path: src/Foundation/Application.php + path: src/Foundation/Exception/Handler.php - message: "#^Conditional return type uses subject type TCacheValue which is not part of PHPDoc @template tags\\.$#" @@ -800,6 +800,11 @@ parameters: count: 1 path: src/Mail/Mailer.php + - + message: "#^Call to an undefined method Illuminate\\\\Config\\\\Repository\\:\\:package\\(\\)\\.$#" + count: 1 + path: src/Support/ModuleServiceProvider.php + - message: "#^Parameter \\#2 \\$data \\(array\\) of method Winter\\\\Storm\\\\Support\\\\Testing\\\\Fakes\\\\MailFake\\:\\:queue\\(\\) should be compatible with parameter \\$queue \\(string\\|null\\) of method Illuminate\\\\Contracts\\\\Mail\\\\MailQueue\\:\\:queue\\(\\)$#" count: 1 diff --git a/src/Database/Connections/Connection.php b/src/Database/Connections/Connection.php index 062c6205c..e42c91f50 100644 --- a/src/Database/Connections/Connection.php +++ b/src/Database/Connections/Connection.php @@ -69,6 +69,6 @@ protected function fireEvent(string $event, array|object $attributes = []): void return; } - $eventManager->fire($event, $attributes); + $eventManager->dispatch($event, $attributes); } } diff --git a/src/Database/DatabaseServiceProvider.php b/src/Database/DatabaseServiceProvider.php index de3db8c3f..abfd728fc 100644 --- a/src/Database/DatabaseServiceProvider.php +++ b/src/Database/DatabaseServiceProvider.php @@ -58,7 +58,7 @@ public function register() $this->app->bind('db.schema', function ($app) { $builder = $app['db']->connection()->getSchemaBuilder(); - $app['events']->fire('db.schema.getBuilder', [$builder]); + $app['events']->dispatch('db.schema.getBuilder', [$builder]); return $builder; }); diff --git a/src/Foundation/Application.php b/src/Foundation/Application.php index 92ee21442..361f3c710 100644 --- a/src/Foundation/Application.php +++ b/src/Foundation/Application.php @@ -129,7 +129,7 @@ public function bootstrapWith(array $bootstrappers) $exceptions = []; foreach ($bootstrappers as $bootstrapper) { - $this['events']->fire('bootstrapping: '.$bootstrapper, [$this]); + $this['events']->dispatch('bootstrapping: '.$bootstrapper, [$this]); // Defer any exceptions until after the application has been // bootstrapped so that the exception handler can run without issues @@ -139,7 +139,7 @@ public function bootstrapWith(array $bootstrappers) $exceptions[] = $ex; } - $this['events']->fire('bootstrapped: '.$bootstrapper, [$this]); + $this['events']->dispatch('bootstrapped: '.$bootstrapper, [$this]); } if (!empty($exceptions)) { @@ -385,7 +385,7 @@ public function setLocale($locale) { parent::setLocale($locale); - $this['events']->fire('locale.changed', [$locale]); + $this['events']->dispatch('locale.changed', [$locale]); } /** diff --git a/src/Foundation/Console/ClearCompiledCommand.php b/src/Foundation/Console/ClearCompiledCommand.php index 5348386e7..9d8a0d36b 100644 --- a/src/Foundation/Console/ClearCompiledCommand.php +++ b/src/Foundation/Console/ClearCompiledCommand.php @@ -2,6 +2,9 @@ use Illuminate\Foundation\Console\ClearCompiledCommand as ClearCompiledCommandBase; +/** + * @property \Winter\Storm\Foundation\Application $laravel + */ class ClearCompiledCommand extends ClearCompiledCommandBase { /** diff --git a/src/Foundation/Console/Kernel.php b/src/Foundation/Console/Kernel.php index 148bf6424..4071ae78f 100644 --- a/src/Foundation/Console/Kernel.php +++ b/src/Foundation/Console/Kernel.php @@ -42,6 +42,6 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $this->bootstrap(); - $this->app['events']->fire('console.schedule', [$schedule]); + $this->app['events']->dispatch('console.schedule', [$schedule]); } } diff --git a/src/Mail/MailManager.php b/src/Mail/MailManager.php index 45ee036d9..6017fae2a 100644 --- a/src/Mail/MailManager.php +++ b/src/Mail/MailManager.php @@ -22,7 +22,7 @@ public function mailer($name = null) /* * Extensibility */ - $this->app['events']->fire('mailer.beforeRegister', [$this]); + $this->app['events']->dispatch('mailer.beforeRegister', [$this]); return parent::mailer($name); } @@ -68,7 +68,7 @@ protected function resolve($name) /* * Extensibility */ - $this->app['events']->fire('mailer.register', [$this, $mailer]); + $this->app['events']->dispatch('mailer.register', [$this, $mailer]); return $mailer; } diff --git a/src/Router/CoreRouter.php b/src/Router/CoreRouter.php index bbc905a7b..ee3a956cb 100644 --- a/src/Router/CoreRouter.php +++ b/src/Router/CoreRouter.php @@ -15,11 +15,11 @@ public function dispatch(Request $request) { $this->currentRequest = $request; - $this->events->fire('router.before', [$request]); + $this->events->dispatch('router.before', [$request]); $response = $this->dispatchToRoute($request); - $this->events->fire('router.after', [$request, $response]); + $this->events->dispatch('router.after', [$request, $response]); return $response; } diff --git a/src/Support/Facades/Schema.php b/src/Support/Facades/Schema.php index b3c38ce20..e1290f76f 100644 --- a/src/Support/Facades/Schema.php +++ b/src/Support/Facades/Schema.php @@ -37,7 +37,7 @@ public static function connection($name) { $builder = static::$app['db']->connection($name)->getSchemaBuilder(); - static::$app['events']->fire('db.schema.getBuilder', [$builder]); + static::$app['events']->dispatch('db.schema.getBuilder', [$builder]); return $builder; } diff --git a/tests/Events/DispatcherTest.php b/tests/Events/DispatcherTest.php index 8cbb8648d..7884ff4da 100644 --- a/tests/Events/DispatcherTest.php +++ b/tests/Events/DispatcherTest.php @@ -36,7 +36,7 @@ public function testNormalListen() $dispatcher->listen('test.test', function () use (&$magic_value) { $magic_value = true; }); - $dispatcher->fire('test.test'); + $dispatcher->dispatch('test.test'); $this->assertTrue($magic_value); } @@ -170,7 +170,7 @@ public function testInstanceMethodListen() $classInstance = new TestClass; $dispatcher->listen('test.test', [$classInstance, 'instanceMethodHandler']); - $dispatcher->fire('test.test'); + $dispatcher->dispatch('test.test'); $this->assertTrue($classInstance->getMagicValue()); } diff --git a/tests/Support/EventFakeTest.php b/tests/Support/EventFakeTest.php index f1c08d7a4..f6654e235 100644 --- a/tests/Support/EventFakeTest.php +++ b/tests/Support/EventFakeTest.php @@ -14,7 +14,7 @@ public function testFire() { $event = 'event.fake.test'; - $this->faker->fire($event); + $this->faker->dispatch($event); $this->faker->assertDispatched($event); } }