From 5f0752e8745f194c3952bbc1c6cfef3132e79c90 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 26 Nov 2021 15:28:43 +0100 Subject: [PATCH] applied changes from code review --- src/Concerns/Extendable.php | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/Concerns/Extendable.php b/src/Concerns/Extendable.php index e569aa47..8713de72 100644 --- a/src/Concerns/Extendable.php +++ b/src/Concerns/Extendable.php @@ -19,7 +19,7 @@ trait Extendable */ private static array $extends = []; - /** @var array> */ + /** @var array> */ private static array $pipes = []; /** @@ -49,9 +49,8 @@ trait Extendable }; } - //@phpstan-ignore-next-line self::pipe($name, function ($next, ...$arguments) use ($handler, $filter) { - //@phpstan-ignore-next-line + /** @phpstan-ignore-next-line */ if ($filter($this->value)) { //@phpstan-ignore-next-line $handler->bindTo($this, get_class($this))(...$arguments); @@ -71,30 +70,12 @@ trait Extendable return array_key_exists($name, static::$extends); } - /** - * Checks if pipes are registered for a given expectation. - */ - public static function hasPipes(string $name): bool - { - return array_key_exists($name, static::$pipes); - } - /** * @return array */ - public function pipes(string $name, object $context, string $scope): array + private function pipes(string $name, object $context, string $scope): array { - if (!self::hasPipes($name)) { - return []; - } - - $decorators = []; - foreach (self::$pipes[$name] as $decorator) { - $decorators[] = $decorator->bindTo($context, $scope); - } - - //@phpstan-ignore-next-line - return $decorators; + return array_map(fn(Closure $pipe) => $pipe->bindTo($context, $scope), self::$pipes[$name] ?? []); } /**