improves static analysis

This commit is contained in:
Fabio Ivona
2021-11-01 10:40:39 +01:00
parent 602403eb59
commit be58d5517a

View File

@ -20,7 +20,7 @@ trait Extendable
*/ */
private static array $extends = []; private static array $extends = [];
/** @var array<string, array<Closure(Closure $next, mixed ...$arguments): void>> */ /** @var array<string, array<Closure(Closure, mixed ...$arguments): void>> */
private static array $pipes = []; private static array $pipes = [];
/** /**
@ -74,14 +74,6 @@ trait Extendable
}); });
} }
/**
* 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. * 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 private function pipes(string $name, object $context, string $scope): array
{ {
if (!self::hasPipes($name)) { return array_map(fn (Closure $pipe) => $pipe->bindTo($context, $scope), self::$pipes[$name] ?? []);
return [];
}
$pipes = [];
foreach (self::$pipes[$name] as $pipe) {
$pipe = $pipe->bindTo($context, $scope);
if ($pipe instanceof Closure) {
$pipes[] = $pipe;
}
}
return $pipes;
} }
/** /**