From 4a22c5d6731ef3ec24d873a8c11269774b9e18af Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Sun, 31 Oct 2021 22:08:34 +0100 Subject: [PATCH] addresses reviews --- src/Concerns/Extendable.php | 22 +++++++++++----------- src/Support/ExpectationPipeline.php | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Concerns/Extendable.php b/src/Concerns/Extendable.php index 792be193..ead03d01 100644 --- a/src/Concerns/Extendable.php +++ b/src/Concerns/Extendable.php @@ -7,7 +7,6 @@ namespace Pest\Concerns; use BadMethodCallException; use Closure; use Pest\Expectation; -use PHPStan\Type\CallableType; /** * @internal @@ -50,6 +49,9 @@ trait Extendable /** * Register an interceptor that should replace an existing expectation. + * + * @param class-string|Closure(mixed $value, mixed ...$arguments): bool $filter + * @param Closure(mixed ...$arguments): void $handler */ public static function intercept(string $name, string|Closure $filter, Closure $handler): void { @@ -58,19 +60,17 @@ trait Extendable } self::pipe($name, function ($next, ...$arguments) use ($handler, $filter): void { - /** @phpstan-ignore-next-line */ - if ($filter($this->value, ...$arguments)) { - /** @phpstan-ignore-next-line */ - $handler = $handler->bindTo($this, get_class($this)); - - if($handler instanceof Closure){ - $handler(...$arguments); - } + /* @phpstan-ignore-next-line */ + if (!$filter($this->value, ...$arguments)) { + $next(); return; } - $next(); + /** @phpstan-ignore-next-line */ + $handler = $handler->bindTo($this, $this::class); + + $handler(...$arguments); }); } @@ -97,7 +97,7 @@ trait Extendable foreach (self::$pipes[$name] as $pipe) { $pipe = $pipe->bindTo($context, $scope); - if($pipe instanceof Closure){ + if ($pipe instanceof Closure) { $pipes[] = $pipe; } } diff --git a/src/Support/ExpectationPipeline.php b/src/Support/ExpectationPipeline.php index 557c82e5..144a2c0f 100644 --- a/src/Support/ExpectationPipeline.php +++ b/src/Support/ExpectationPipeline.php @@ -14,7 +14,7 @@ final class ExpectationPipeline /** @var array */ private array $pipes = []; - /** @var array */ + /** @var array */ private array $passable; public function __construct( @@ -28,7 +28,7 @@ final class ExpectationPipeline return new self($expectationClosure); } - public function send(...$passable): ExpectationPipeline + public function send(mixed ...$passable): ExpectationPipeline { $this->passable = $passable;