From d3feb77ce9c644a250a186d98e6940e343a053f9 Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Sat, 8 May 2021 15:11:54 +0200 Subject: [PATCH] fixed parameter types --- flight/core/Dispatcher.php | 31 ++++++++++++++++--------------- flight/core/Loader.php | 4 ++-- flight/net/Route.php | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 5652fcd..50b73f0 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace flight\core; use Exception; +use InvalidArgumentException; /** * The Dispatcher class is responsible for dispatching events. Events @@ -38,9 +39,9 @@ class Dispatcher * *@throws Exception * - * @return string Output of callback + * @return mixed|null Output of callback */ - public function run(string $name, array $params = []): ?string + final public function run(string $name, array $params = []) { $output = ''; @@ -50,7 +51,7 @@ class Dispatcher } // Run requested method - $output = $this->execute($this->get($name), $params); + $output = self::execute($this->get($name), $params); // Run post-filters if (!empty($this->filters[$name]['after'])) { @@ -66,7 +67,7 @@ class Dispatcher * @param string $name Event name * @param callback $callback Callback function */ - public function set(string $name, callable $callback): void + final public function set(string $name, callable $callback): void { $this->events[$name] = $callback; } @@ -78,7 +79,7 @@ class Dispatcher * * @return callback $callback Callback function */ - public function get(string $name): ?callable + final public function get(string $name): ?callable { return $this->events[$name] ?? null; } @@ -90,7 +91,7 @@ class Dispatcher * * @return bool Event status */ - public function has(string $name): bool + final public function has(string $name): bool { return isset($this->events[$name]); } @@ -101,7 +102,7 @@ class Dispatcher * * @param string|null $name Event name */ - public function clear(?string $name = null): void + final public function clear(?string $name = null): void { if (null !== $name) { unset($this->events[$name]); @@ -119,7 +120,7 @@ class Dispatcher * @param string $type Filter type * @param callback $callback Callback function */ - public function hook(string $name, string $type, callable $callback) + final public function hook(string $name, string $type, callable $callback): void { $this->filters[$name][$type][] = $callback; } @@ -133,11 +134,11 @@ class Dispatcher * * @throws Exception */ - public function filter(array $filters, array &$params, &$output): void + final public function filter(array $filters, array &$params, &$output): void { $args = [&$params, &$output]; foreach ($filters as $callback) { - $continue = $this->execute($callback, $args); + $continue = self::execute($callback, $args); if (false === $continue) { break; } @@ -147,14 +148,14 @@ class Dispatcher /** * Executes a callback function. * - * @param callback $callback Callback function - * @param array $params Function parameters + * @param array|callback $callback Callback function + * @param array $params Function parameters * *@throws Exception * * @return mixed Function results */ - public static function execute(callable $callback, array &$params = []) + public static function execute($callback, array &$params = []) { if (\is_callable($callback)) { return \is_array($callback) ? @@ -162,7 +163,7 @@ class Dispatcher self::callFunction($callback, $params); } - throw new Exception('Invalid callback specified.'); + throw new InvalidArgumentException('Invalid callback specified.'); } /** @@ -245,7 +246,7 @@ class Dispatcher /** * Resets the object to the initial state. */ - public function reset(): void + final public function reset(): void { $this->events = []; $this->filters = []; diff --git a/flight/core/Loader.php b/flight/core/Loader.php index 4520b32..95874a6 100644 --- a/flight/core/Loader.php +++ b/flight/core/Loader.php @@ -179,9 +179,9 @@ class Loader * Starts/stops autoloader. * * @param bool $enabled Enable/disable autoloading - * @param array $dirs Autoload directories + * @param mixed $dirs Autoload directories */ - public static function autoload(bool $enabled = true, array $dirs = []): void + public static function autoload(bool $enabled = true, $dirs = []): void { if ($enabled) { spl_autoload_register([__CLASS__, 'loadClass']); diff --git a/flight/net/Route.php b/flight/net/Route.php index f82536a..91a6aff 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -40,7 +40,7 @@ final class Route /** * @var string|null Matching regular expression */ - public ?string $regex; + public ?string $regex = null; /** * @var string URL splat content