Skip to content

Commit

Permalink
Accept Throwable for onRejected and expand return type for wait() (#30)
Browse files Browse the repository at this point in the history
* Add PHPStan checks to PRs
* Use conditional return type in PHPDoc for wait()
  • Loading branch information
Ndiritu authored Nov 8, 2023
1 parent ef4905b commit 7fa2284
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ jobs:
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: PHPStan
uses: OskarStark/[email protected]
env:
REQUIRE_DEV: false
with:
args: analyze --no-progress
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.2.1

### Added

- Fixed PHPDoc for `wait()` and `then()`'s `onRejected` callable

## 1.2.0 - 2023-10-24

### Added
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: max
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
paths:
- src
2 changes: 2 additions & 0 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ public function wait($unwrap = true)
if ($unwrap) {
return $this->result;
}

return;
}
}
4 changes: 2 additions & 2 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface Promise
* The callback will be called when the value arrived and never more than once.
*
* @param callable(T): V|null $onFulfilled called when a response will be available
* @param callable(\Exception): V|null $onRejected called when an exception occurs
* @param callable(\Throwable): V|null $onRejected called when an exception occurs
*
* @return Promise<V> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
*
Expand All @@ -65,7 +65,7 @@ public function getState();
*
* @param bool $unwrap Whether to return resolved value / throw reason or not
*
* @return T Resolved value, null if $unwrap is set to false
* @return ($unwrap is true ? T : null) Resolved value, null if $unwrap is set to false
*
* @throws \Exception the rejection reason if $unwrap is set to true and the request failed
*/
Expand Down
2 changes: 2 additions & 0 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ public function wait($unwrap = true)
if ($unwrap) {
throw $this->exception;
}

return;
}
}

0 comments on commit 7fa2284

Please sign in to comment.