Skip to content

Commit

Permalink
Merge pull request #33 from php-http/phpdoc-revert
Browse files Browse the repository at this point in the history
revert generic annotations
  • Loading branch information
dbu authored Jan 4, 2024
2 parents 44a67cb + 2916a60 commit 13d7636
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Remove phpspec
run: composer remove --dev friends-of-phpspec/phpspec-code-coverage phpspec/phpspec

- name: PHPStan
uses: OskarStark/[email protected]
env:
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Change Log

## 1.2.1
## 1.3.0 - 2024-01-04

### Added - 2023-11-08
### Fixed

- Reverted generic annotations on promise - as `then` returns another promise, there seems no way to properly document this.

## 1.2.1 - 2023-11-08

### Added

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

Expand Down
19 changes: 3 additions & 16 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@
* A promise already fulfilled.
*
* @author Joel Wurtz <[email protected]>
*
* @template-covariant T
*
* @implements Promise<T>
*/
final class FulfilledPromise implements Promise
{
/**
* @var T
* @var mixed
*/
private $result;

/**
* @param T $result
* @param mixed $result
*/
public function __construct($result)
{
$this->result = $result;
}

/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
if (null === $onFulfilled) {
Expand All @@ -42,23 +35,17 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
}
}

/**
* {@inheritdoc}
*/
public function getState()
{
return Promise::FULFILLED;
}

/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
if ($unwrap) {
return $this->result;
}

return;
return null;
}
}
14 changes: 5 additions & 9 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*
* @author Joel Wurtz <[email protected]>
* @author Márk Sági-Kazár <[email protected]>
*
* @template-covariant T
*/
interface Promise
{
Expand All @@ -38,12 +36,10 @@ interface Promise
* If you do not care about one of the cases, you can set the corresponding callable to null
* 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(\Throwable): V|null $onRejected called when an exception occurs
*
* @return Promise<V> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
* @param callable|null $onFulfilled called when a response will be available
* @param callable|null $onRejected called when an exception occurs
*
* @template V
* @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected)
*/
public function then(callable $onFulfilled = null, callable $onRejected = null);

Expand All @@ -65,9 +61,9 @@ public function getState();
*
* @param bool $unwrap Whether to return resolved value / throw reason or not
*
* @return ($unwrap is true ? T : null) Resolved value, null if $unwrap is set to false
* @return ($unwrap is true ? mixed : 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
* @throws \Throwable the rejection reason if $unwrap is set to true and the request failed
*/
public function wait($unwrap = true);
}
19 changes: 3 additions & 16 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,19 @@
* A rejected promise.
*
* @author Joel Wurtz <[email protected]>
*
* @template-covariant T
*
* @implements Promise<T>
*/
final class RejectedPromise implements Promise
{
/**
* @var \Exception
* @var \Throwable
*/
private $exception;

public function __construct(\Exception $exception)
public function __construct(\Throwable $exception)
{
$this->exception = $exception;
}

/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
if (null === $onRejected) {
Expand All @@ -39,23 +32,17 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)
}
}

/**
* {@inheritdoc}
*/
public function getState()
{
return Promise::REJECTED;
}

/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
if ($unwrap) {
throw $this->exception;
}

return;
return null;
}
}

0 comments on commit 13d7636

Please sign in to comment.