Skip to content

Commit

Permalink
use Psalm v5
Browse files Browse the repository at this point in the history
  • Loading branch information
someniatko committed Nov 22, 2024
1 parent 036c382 commit de3c6d1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<projectFiles>
<directory name="src"/>
Expand Down
6 changes: 6 additions & 0 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/None.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit de3c6d1

Please sign in to comment.