diff --git a/README.md b/README.md index 3ddf44a..0f352e0 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ At the moment, in the experimental phase. **[Documentation](https://munusphp.github.io/docs/start)** -Due to the lack of generic types, Munus achieves genericity with the help of [Psalm](https://github.com/vimeo/psalm) `template` annotation. +Due to the lack of generic types, Munus achieves genericity with the help of [PHPStan](https://phpstan.org/blog/generics-in-php-using-phpdocs) `template` annotation. Stream example: find the sum of the first ten squares of even numbers ```php diff --git a/composer.json b/composer.json index c00de44..dc9b5d5 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.9", "phpunit/phpunit": "^8.4", - "vimeo/psalm": "^4.9", - "phpstan/phpstan": "^0.12", - "psalm/plugin-phpunit": "^0.15" + "phpstan/phpstan": "^1.9" }, "autoload": { "psr-4": { @@ -44,9 +42,6 @@ "phpstan": [ "phpstan analyse src tests --level=4" ], - "psalm": [ - "psalm --show-info=false" - ], "phpunit": [ "phpunit --color=always" ], diff --git a/psalm.baseline.xml b/psalm.baseline.xml deleted file mode 100644 index 4f03a57..0000000 --- a/psalm.baseline.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - $this->tail()->map($mapper) - - - - - $this->map - $this->map - - - (string) $key - - - - - - - - call_user_func($transformer, ...$this->data->toArray()) - - - - - function (string $a, string $b): string {return $a.$b; } - - - - - equals - equals - - - - - function (int $a, int $b): int {return $a + $b; } - - - - - function (int $a, int $b): int {return $a + $b; } - - - $name === 'munus' - - - diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 2b86e77..0000000 --- a/psalm.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Collection/Iterator.php b/src/Collection/Iterator.php index 36ae910..8d87257 100644 --- a/src/Collection/Iterator.php +++ b/src/Collection/Iterator.php @@ -140,7 +140,7 @@ public function reduce(callable $operation) } $accumulator = $this->next(); - while ($this->hasNext()) { + while ($this->hasNext()) { // @phpstan-ignore-line $accumulator = $operation($accumulator, $this->next()); } diff --git a/src/Collection/Map.php b/src/Collection/Map.php index c1a9cb4..808dfb9 100644 --- a/src/Collection/Map.php +++ b/src/Collection/Map.php @@ -77,7 +77,10 @@ public function get(): Option } $key = func_get_arg(0); - return isset($this->map[$key]) ? Option::some($this->map[$key]) : Option::none(); + /** @var Option $option */ + $option = isset($this->map[$key]) ? Option::some($this->map[$key]) : Option::none(); + + return $option; } /** diff --git a/src/Control/Option.php b/src/Control/Option.php index 1fec587..3cbaba9 100644 --- a/src/Control/Option.php +++ b/src/Control/Option.php @@ -24,7 +24,10 @@ abstract class Option extends Value */ public static function of($value): self { - return $value === null ? self::none() : self::some($value); + /** @var Option $option */ + $option = $value === null ? self::none() : self::some($value); + + return $option; } /** diff --git a/tests/Collection/IteratorTest.php b/tests/Collection/IteratorTest.php index d5ac536..7cb244b 100644 --- a/tests/Collection/IteratorTest.php +++ b/tests/Collection/IteratorTest.php @@ -73,4 +73,11 @@ public function testCompositeIterator(): void self::assertEquals(4, $iterator->next()); self::assertFalse($iterator->hasNext()); } + + public function testReduce(): void + { + $iterator = Iterator::of(1, 2, 3); + + self::assertEquals(6, $iterator->reduce(fn (int $a, int $b) => $a + $b)); + } }