Skip to content

Commit 7fa2284

Browse files
authored
Accept Throwable for onRejected and expand return type for wait() (#30)
* Add PHPStan checks to PRs * Use conditional return type in PHPDoc for wait()
1 parent ef4905b commit 7fa2284

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

.github/workflows/tests.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,18 @@ jobs:
6060
run: |
6161
wget https://scrutinizer-ci.com/ocular.phar
6262
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml
63+
64+
phpstan:
65+
name: PHPStan
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v3
71+
72+
- name: PHPStan
73+
uses: OskarStark/phpstan-ga@0.12.32
74+
env:
75+
REQUIRE_DEV: false
76+
with:
77+
args: analyze --no-progress

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 1.2.1
4+
5+
### Added
6+
7+
- Fixed PHPDoc for `wait()` and `then()`'s `onRejected` callable
8+
39
## 1.2.0 - 2023-10-24
410

511
### Added

phpstan.neon.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: max
3+
checkMissingIterableValueType: false
4+
treatPhpDocTypesAsCertain: false
5+
paths:
6+
- src

src/FulfilledPromise.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ public function wait($unwrap = true)
5858
if ($unwrap) {
5959
return $this->result;
6060
}
61+
62+
return;
6163
}
6264
}

src/Promise.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface Promise
3939
* The callback will be called when the value arrived and never more than once.
4040
*
4141
* @param callable(T): V|null $onFulfilled called when a response will be available
42-
* @param callable(\Exception): V|null $onRejected called when an exception occurs
42+
* @param callable(\Throwable): V|null $onRejected called when an exception occurs
4343
*
4444
* @return Promise<V> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
4545
*
@@ -65,7 +65,7 @@ public function getState();
6565
*
6666
* @param bool $unwrap Whether to return resolved value / throw reason or not
6767
*
68-
* @return T Resolved value, null if $unwrap is set to false
68+
* @return ($unwrap is true ? T : null) Resolved value, null if $unwrap is set to false
6969
*
7070
* @throws \Exception the rejection reason if $unwrap is set to true and the request failed
7171
*/

src/RejectedPromise.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ public function wait($unwrap = true)
5555
if ($unwrap) {
5656
throw $this->exception;
5757
}
58+
59+
return;
5860
}
5961
}

0 commit comments

Comments
 (0)