From d192d12ae88f1165a38741c3ac8c9cf6498d3d36 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Fri, 3 Nov 2023 22:29:13 +0300 Subject: [PATCH 1/6] Accept Throwable for onRejected and expand return type for wait() --- src/Promise.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Promise.php b/src/Promise.php index 9383726..20f5f2e 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -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 a new resolved promise with value of the executed callback (onFulfilled / onRejected) * @@ -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 T|void|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 */ From 8f40b17fba92378c18d0ed7b9b6edd9f5270911f Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 7 Nov 2023 22:53:27 +0300 Subject: [PATCH 2/6] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b57b33b..fafc207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 5023f600275743f56e672b1e6c941255dc47ecb1 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 7 Nov 2023 23:12:35 +0300 Subject: [PATCH 3/6] Add PHPStan checks to PRs --- .github/workflows/tests.yml | 15 +++++++++++++++ phpstan.neon.dist | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 phpstan.neon.dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4e8cc27..60d4f7a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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/phpstan-ga@0.12.32 + env: + REQUIRE_DEV: false + with: + args: analyze --no-progress diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..f8b94cf --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,6 @@ +parameters: + level: max + checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false + paths: + - src From 5ae1e369e794996561efed8a28fac4e86a2644c7 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Wed, 8 Nov 2023 10:51:54 +0300 Subject: [PATCH 4/6] Use conditional return type in PHPDoc for wait() --- src/Promise.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Promise.php b/src/Promise.php index 20f5f2e..c53840a 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -65,7 +65,7 @@ public function getState(); * * @param bool $unwrap Whether to return resolved value / throw reason or not * - * @return T|void|null Resolved value, null if $unwrap is set to false + * @return ($unwrap is true ? T : null|void) Resolved value, null if $unwrap is set to false * * @throws \Exception the rejection reason if $unwrap is set to true and the request failed */ From 7d36efcfa329310e0efb2583a5f591b4b14547a3 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Wed, 8 Nov 2023 13:54:41 +0300 Subject: [PATCH 5/6] Update conditional return type of wait() --- src/FulfilledPromise.php | 1 + src/Promise.php | 2 +- src/RejectedPromise.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FulfilledPromise.php b/src/FulfilledPromise.php index dce0431..02f027a 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -58,5 +58,6 @@ public function wait($unwrap = true) if ($unwrap) { return $this->result; } + return; } } diff --git a/src/Promise.php b/src/Promise.php index c53840a..81434ae 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -65,7 +65,7 @@ public function getState(); * * @param bool $unwrap Whether to return resolved value / throw reason or not * - * @return ($unwrap is true ? T : null|void) 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 */ diff --git a/src/RejectedPromise.php b/src/RejectedPromise.php index 2cbefec..3faf074 100644 --- a/src/RejectedPromise.php +++ b/src/RejectedPromise.php @@ -55,5 +55,6 @@ public function wait($unwrap = true) if ($unwrap) { throw $this->exception; } + return; } } From 35f913887168209cb4d3d3050a99b5c303230b9e Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Wed, 8 Nov 2023 14:08:41 +0300 Subject: [PATCH 6/6] Fix style-ci issues --- src/FulfilledPromise.php | 1 + src/RejectedPromise.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/FulfilledPromise.php b/src/FulfilledPromise.php index 02f027a..c9158e7 100644 --- a/src/FulfilledPromise.php +++ b/src/FulfilledPromise.php @@ -58,6 +58,7 @@ public function wait($unwrap = true) if ($unwrap) { return $this->result; } + return; } } diff --git a/src/RejectedPromise.php b/src/RejectedPromise.php index 3faf074..a500048 100644 --- a/src/RejectedPromise.php +++ b/src/RejectedPromise.php @@ -55,6 +55,7 @@ public function wait($unwrap = true) if ($unwrap) { throw $this->exception; } + return; } }