From be58d5517a738150e1340bb487f2c4e75a4b431d Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 1 Nov 2021 10:40:39 +0100 Subject: [PATCH] improves static analysis --- src/Concerns/Extendable.php | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Concerns/Extendable.php b/src/Concerns/Extendable.php index a8ff0ab0..031c8b30 100644 --- a/src/Concerns/Extendable.php +++ b/src/Concerns/Extendable.php @@ -20,7 +20,7 @@ trait Extendable */ private static array $extends = []; - /** @var array> */ + /** @var array> */ private static array $pipes = []; /** @@ -60,28 +60,20 @@ trait Extendable } self::pipe($name, function ($next, ...$arguments) use ($handler, $filter): void { - /* @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ if (!$filter($this->value, ...$arguments)) { $next(); return; } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line */ $handler = $handler->bindTo($this, $this::class); $handler(...$arguments); }); } - /** - * Checks if pipes are registered for a given expectation. - */ - private static function hasPipes(string $name): bool - { - return array_key_exists($name, static::$pipes); - } - /** * Gets the pipes that have been registered for a given expectation and binds them to a context and a scope. * @@ -89,20 +81,7 @@ trait Extendable */ private function pipes(string $name, object $context, string $scope): array { - if (!self::hasPipes($name)) { - return []; - } - - $pipes = []; - foreach (self::$pipes[$name] as $pipe) { - $pipe = $pipe->bindTo($context, $scope); - - if ($pipe instanceof Closure) { - $pipes[] = $pipe; - } - } - - return $pipes; + return array_map(fn (Closure $pipe) => $pipe->bindTo($context, $scope), self::$pipes[$name] ?? []); } /**