Skip to content

Commit

Permalink
revert generic annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 4, 2024
1 parent 44a67cb commit 63fceaf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 43 deletions.
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 - unreleased

### 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 63fceaf

Please sign in to comment.