diff --git a/composer.json b/composer.json index 99270e3..c0f7dd3 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ }, "require-dev": { "phpunit/phpunit": "^9.5", - "vimeo/psalm": "^4.7", - "psalm/plugin-phpunit": "^0.17", + "vimeo/psalm": "^5", + "psalm/plugin-phpunit": "^0.18", "squizlabs/php_codesniffer": "^3.6" }, "autoload": { diff --git a/psalm.xml b/psalm.xml index 550298b..0b8cb4c 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,6 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config https://raw.githubusercontent.com/vimeo/psalm/master/config.xsd" + findUnusedBaselineEntry="true" + findUnusedCode="false" > diff --git a/src/Error.php b/src/Error.php index 44ef760..69c3be1 100644 --- a/src/Error.php +++ b/src/Error.php @@ -43,6 +43,12 @@ public function get() return $this->value; } + /** + * @template TNewError + * + * @param callable(TError):TNewError $map + * @return TNewError + */ public function getOr(callable $map) { return $map($this->value); diff --git a/src/None.php b/src/None.php index 09c0509..4b3bfc1 100644 --- a/src/None.php +++ b/src/None.php @@ -20,11 +20,21 @@ public function flatMap(callable $map): Option return $this; } + /** + * @template TElse + * @param callable():TElse $else + * @return TElse + */ public function getOr(callable $else) { return $else(); } + /** + * @template TElse + * @param TElse $else + * @return TElse + */ public function getOrElse($else) { return $else; diff --git a/test/ResultTest.php b/test/ResultTest.php index a8921f0..0b73be2 100644 --- a/test/ResultTest.php +++ b/test/ResultTest.php @@ -191,6 +191,7 @@ public function testEnsureSuccessReturningFalse(): void public function testEnsureErrorDoesNotChangePreviousError(): void { $result = Result::error('old error'); + /** @psalm-var Result $result */ $ensured = $result->ensure(fn(int $i) => $i > 100, 'new error'); self::assertEquals('old error', $ensured->get()); }