diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 31116b9..912f910 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,20 +1,10 @@ parameters: ignoreErrors: - - - message: "#^Trying to invoke \\(callable\\(\\)\\: mixed\\)\\|null but it might not be a callable\\.$#" - count: 2 - path: src/Builders/AbstractParameterizedQueryBuilder.php - - message: "#^Method Elastic\\\\ScoutDriverPlus\\\\Builders\\\\SearchParametersBuilder\\:\\:resolveJoinedIndexName\\(\\) should return string but returns mixed\\.$#" count: 1 path: src/Builders/SearchParametersBuilder.php - - - message: "#^Trying to invoke \\(callable\\(\\)\\: mixed\\)\\|null but it might not be a callable\\.$#" - count: 2 - path: src/Builders/SearchParametersBuilder.php - - message: "#^Parameter \\#1 \\$items of class Illuminate\\\\Database\\\\Eloquent\\\\Collection constructor expects Illuminate\\\\Contracts\\\\Support\\\\Arrayable\\\\|iterable\\\\|null, Illuminate\\\\Support\\\\Collection\\ given\\.$#" count: 1 diff --git a/src/Support/Conditionable.php b/src/Support/Conditionable.php index a05871b..727b142 100644 --- a/src/Support/Conditionable.php +++ b/src/Support/Conditionable.php @@ -3,30 +3,25 @@ namespace Elastic\ScoutDriverPlus\Support; use Closure; -use Illuminate\Support\HigherOrderWhenProxy; /** - * This trait duplicates \Illuminate\Support\Traits\Conditionable, + * This trait is similar to \Illuminate\Support\Traits\Conditionable, * which is available in Laravel since version 9. */ trait Conditionable { /** * @param mixed $value - * - * @return $this|HigherOrderWhenProxy */ - public function when($value, callable $callback = null, callable $default = null) + public function when($value, callable $callback, callable $default = null): self { $value = $value instanceof Closure ? $value($this) : $value; - if (func_num_args() === 1) { - return new HigherOrderWhenProxy($this, $value); - } - if ($value) { return $callback($this, $value) ?? $this; - } elseif ($default) { + } + + if ($default) { return $default($this, $value) ?? $this; } @@ -36,19 +31,17 @@ public function when($value, callable $callback = null, callable $default = null /** * @param mixed $value * - * @return $this|HigherOrderWhenProxy + * @return $this */ - public function unless($value, callable $callback = null, callable $default = null) + public function unless($value, callable $callback, callable $default = null): self { $value = $value instanceof Closure ? $value($this) : $value; - if (func_num_args() === 1) { - return new HigherOrderWhenProxy($this, ! $value); + if (!$value) { + return $callback($this, $value) ?? $this; } - if (! $value) { - return $callback($this, $value) ?? $this; - } elseif ($default) { + if ($default) { return $default($this, $value) ?? $this; }