mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 02:07:23 +01:00
improves static analysis
This commit is contained in:
@ -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 = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,28 +60,20 @@ trait Extendable
|
|||||||
}
|
}
|
||||||
|
|
||||||
self::pipe($name, function ($next, ...$arguments) use ($handler, $filter): void {
|
self::pipe($name, function ($next, ...$arguments) use ($handler, $filter): void {
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
if (!$filter($this->value, ...$arguments)) {
|
if (!$filter($this->value, ...$arguments)) {
|
||||||
$next();
|
$next();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @phpstan-ignore-next-line */
|
/** @phpstan-ignore-next-line */
|
||||||
$handler = $handler->bindTo($this, $this::class);
|
$handler = $handler->bindTo($this, $this::class);
|
||||||
|
|
||||||
$handler(...$arguments);
|
$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.
|
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user