mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 10:17:23 +01:00
applied changes from code review
This commit is contained in:
@ -19,7 +19,7 @@ trait Extendable
|
|||||||
*/
|
*/
|
||||||
private static array $extends = [];
|
private static array $extends = [];
|
||||||
|
|
||||||
/** @var array<string, array<Closure>> */
|
/** @var array<string, array<Closure(Closure $next, mixed ...$arguments): void>> */
|
||||||
private static array $pipes = [];
|
private static array $pipes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,9 +49,8 @@ trait Extendable
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//@phpstan-ignore-next-line
|
|
||||||
self::pipe($name, function ($next, ...$arguments) use ($handler, $filter) {
|
self::pipe($name, function ($next, ...$arguments) use ($handler, $filter) {
|
||||||
//@phpstan-ignore-next-line
|
/** @phpstan-ignore-next-line */
|
||||||
if ($filter($this->value)) {
|
if ($filter($this->value)) {
|
||||||
//@phpstan-ignore-next-line
|
//@phpstan-ignore-next-line
|
||||||
$handler->bindTo($this, get_class($this))(...$arguments);
|
$handler->bindTo($this, get_class($this))(...$arguments);
|
||||||
@ -71,30 +70,12 @@ trait Extendable
|
|||||||
return array_key_exists($name, static::$extends);
|
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<int, Closure>
|
* @return array<int, Closure>
|
||||||
*/
|
*/
|
||||||
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 array_map(fn(Closure $pipe) => $pipe->bindTo($context, $scope), self::$pipes[$name] ?? []);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$decorators = [];
|
|
||||||
foreach (self::$pipes[$name] as $decorator) {
|
|
||||||
$decorators[] = $decorator->bindTo($context, $scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
//@phpstan-ignore-next-line
|
|
||||||
return $decorators;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user