← All changes
|
includes/sdk/s3/GuzzleHttp/Promise/FulfilledPromise.php
+16
-12
1.2.2
→
1.4.2
View file →
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +declare (strict_types=1); | |
| 3 | 4 | namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Promise; |
| 4 | 5 | |
| 5 | 6 | /** |
| 6 | 7 | * A promise that has been fulfilled. |
| @@ -6,12 +7,17 @@ | ||
| 6 | 7 | * A promise that has been fulfilled. |
| 7 | 8 | * |
| 8 | 9 | * Thenning off of this promise will invoke the onFulfilled callback |
| 9 | 10 | * immediately and ignore other callbacks. |
| 11 | + * | |
| 12 | + * @final | |
| 10 | 13 | */ |
| 11 | 14 | class FulfilledPromise implements PromiseInterface |
| 12 | 15 | { |
| 13 | 16 | private $value; |
| 17 | + /** | |
| 18 | + * @param mixed $value | |
| 19 | + */ | |
| 14 | 20 | public function __construct($value) |
| 15 | 21 | { |
| 16 | 22 | if (\is_object($value) && \method_exists($value, 'then')) { |
| 17 | 23 | throw new \InvalidArgumentException('You cannot create a FulfilledPromise with a promise.'); |
| @@ -17,9 +23,9 @@ | ||
| 17 | 23 | throw new \InvalidArgumentException('You cannot create a FulfilledPromise with a promise.'); |
| 18 | 24 | } |
| 19 | 25 | $this->value = $value; |
| 20 | 26 | } |
| 21 | - public function then(callable $onFulfilled = null, callable $onRejected = null) | |
| 27 | + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface | |
| 22 | 28 | { |
| 23 | 29 | // Return itself if there is no onFulfilled function. |
| 24 | 30 | if (!$onFulfilled) { |
| 25 | 31 | return $this; |
| @@ -26,44 +32,42 @@ | ||
| 26 | 32 | } |
| 27 | 33 | $queue = Utils::queue(); |
| 28 | 34 | $p = new Promise([$queue, 'run']); |
| 29 | 35 | $value = $this->value; |
| 30 | - $queue->add(static function () use($p, $value, $onFulfilled) { | |
| 36 | + $queue->add(static function () use($p, $value, $onFulfilled) : void { | |
| 31 | 37 | if (Is::pending($p)) { |
| 32 | 38 | try { |
| 33 | 39 | $p->resolve($onFulfilled($value)); |
| 34 | 40 | } catch (\Throwable $e) { |
| 35 | 41 | $p->reject($e); |
| 36 | - } catch (\Exception $e) { | |
| 37 | - $p->reject($e); | |
| 38 | 42 | } |
| 39 | 43 | } |
| 40 | 44 | }); |
| 41 | 45 | return $p; |
| 42 | 46 | } |
| 43 | - public function otherwise(callable $onRejected) | |
| 47 | + public function otherwise(callable $onRejected) : PromiseInterface | |
| 44 | 48 | { |
| 45 | 49 | return $this->then(null, $onRejected); |
| 46 | 50 | } |
| 47 | - public function wait($unwrap = \true, $defaultDelivery = null) | |
| 51 | + public function wait(bool $unwrap = \true) | |
| 48 | 52 | { |
| 49 | 53 | return $unwrap ? $this->value : null; |
| 50 | 54 | } |
| 51 | - public function getState() | |
| 55 | + public function getState() : string | |
| 52 | 56 | { |
| 53 | 57 | return self::FULFILLED; |
| 54 | 58 | } |
| 55 | - public function resolve($value) | |
| 59 | + public function resolve($value) : void | |
| 56 | 60 | { |
| 57 | 61 | if ($value !== $this->value) { |
| 58 | - throw new \LogicException("Cannot resolve a fulfilled promise"); | |
| 62 | + throw new \LogicException('Cannot resolve a fulfilled promise'); | |
| 59 | 63 | } |
| 60 | 64 | } |
| 61 | - public function reject($reason) | |
| 65 | + public function reject($reason) : void | |
| 62 | 66 | { |
| 63 | - throw new \LogicException("Cannot reject a fulfilled promise"); | |
| 67 | + throw new \LogicException('Cannot reject a fulfilled promise'); | |
| 64 | 68 | } |
| 65 | - public function cancel() | |
| 69 | + public function cancel() : void | |
| 66 | 70 | { |
| 67 | 71 | // pass |
| 68 | 72 | } |
| 69 | 73 | } |