From db2e259a757531b9fec686cac3f7d27934bfed9d Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Tue, 28 May 2024 08:55:08 +0200 Subject: [PATCH] unlock phpstan --- composer.json | 2 +- .../Stream/Collector/GenericCollector.php | 20 ++++++++----------- src/Collection/Traversable.php | 20 ++----------------- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 68136ff..2ec5f68 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "friendsofphp/php-cs-fixer": "^3.27", "nette/php-generator": "^4.0", "phpunit/phpunit": "^9.6.13", - "phpstan/phpstan": "1.11.1" + "phpstan/phpstan": "^1.11.2" }, "autoload": { "psr-4": { diff --git a/src/Collection/Stream/Collector/GenericCollector.php b/src/Collection/Stream/Collector/GenericCollector.php index b4f3b91..77d2f0d 100644 --- a/src/Collection/Stream/Collector/GenericCollector.php +++ b/src/Collection/Stream/Collector/GenericCollector.php @@ -20,12 +20,12 @@ final class GenericCollector implements Collector private $supplier; /** - * @var callable + * @var callable(R,T):R */ private $accumulator; /** - * @var callable + * @var callable(R):R */ private $finisher; @@ -52,14 +52,10 @@ public function __construct($supplier, callable $accumulator, callable $finisher */ public static function of($supplier, callable $accumulator): self { - return new self($supplier, $accumulator, - /** - * @param W $supplier - * - * @return W - */ - function ($supplier) {return $supplier; } - ); + /** @var self $instance */ + $instance = new self($supplier, $accumulator, fn ($s) => $s); + + return $instance; } /** @@ -67,7 +63,7 @@ function ($supplier) {return $supplier; } */ public function accumulate($value): void { - $this->supplier = call_user_func($this->accumulator, $this->supplier, $value); + $this->supplier = ($this->accumulator)($this->supplier, $value); } /** @@ -75,6 +71,6 @@ public function accumulate($value): void */ public function finish() { - return call_user_func($this->finisher, $this->supplier); + return ($this->finisher)($this->supplier); } } diff --git a/src/Collection/Traversable.php b/src/Collection/Traversable.php index 45a2933..209b187 100644 --- a/src/Collection/Traversable.php +++ b/src/Collection/Traversable.php @@ -339,15 +339,7 @@ public function min(): Option return Option::none(); } - return Option::of($this->fold($this->head(), - /** - * @param T $min - * @param T $x - */ - function ($min, $x) { - return $min <= $x ? $min : $x; - } - )); + return Option::of($this->fold($this->head(), min(...))); } /** @@ -359,15 +351,7 @@ public function max(): Option return Option::none(); } - return Option::of($this->fold($this->head(), - /** - * @param T $max - * @param T $x - */ - function ($max, $x) { - return $max >= $x ? $max : $x; - } - )); + return Option::of($this->fold($this->head(), max(...))); } /**