PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/s3/GuzzleHttp/Promise/RejectedPromise.php +16 -13 1.0.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 rejected.
@@ -6,12 +7,17 @@
6 7 * A promise that has been rejected.
7 8 *
8 9 * Thenning off of this promise will invoke the onRejected callback
9 10 * immediately and ignore other callbacks.
11 + *
12 + * @final
10 13 */
11 14 class RejectedPromise implements PromiseInterface
12 15 {
13 16 private $reason;
17 + /**
18 + * @param mixed $reason
19 + */
14 20 public function __construct($reason)
15 21 {
16 22 if (\is_object($reason) && \method_exists($reason, 'then')) {
17 23 throw new \InvalidArgumentException('You cannot create a RejectedPromise with a promise.');
@@ -17,9 +23,9 @@
17 23 throw new \InvalidArgumentException('You cannot create a RejectedPromise with a promise.');
18 24 }
19 25 $this->reason = $reason;
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 // If there's no onRejected callback then just return self.
24 30 if (!$onRejected) {
25 31 return $this;
@@ -26,9 +32,9 @@
26 32 }
27 33 $queue = Utils::queue();
28 34 $reason = $this->reason;
29 35 $p = new Promise([$queue, 'run']);
30 - $queue->add(static function () use($p, $reason, $onRejected) {
36 + $queue->add(static function () use($p, $reason, $onRejected) : void {
31 37 if (Is::pending($p)) {
32 38 try {
33 39 // Return a resolved promise if onRejected does not throw.
34 40 $p->resolve($onRejected($reason));
@@ -34,21 +40,18 @@
34 40 $p->resolve($onRejected($reason));
35 41 } catch (\Throwable $e) {
36 42 // onRejected threw, so return a rejected promise.
37 43 $p->reject($e);
38 - } catch (\Exception $e) {
39 - // onRejected threw, so return a rejected promise.
40 - $p->reject($e);
41 44 }
42 45 }
43 46 });
44 47 return $p;
45 48 }
46 - public function otherwise(callable $onRejected)
49 + public function otherwise(callable $onRejected) : PromiseInterface
47 50 {
48 51 return $this->then(null, $onRejected);
49 52 }
50 - public function wait($unwrap = \true, $defaultDelivery = null)
53 + public function wait(bool $unwrap = \true)
51 54 {
52 55 if ($unwrap) {
53 56 throw Create::exceptionFor($this->reason);
54 57 }
@@ -53,23 +56,23 @@
53 56 throw Create::exceptionFor($this->reason);
54 57 }
55 58 return null;
56 59 }
57 - public function getState()
60 + public function getState() : string
58 61 {
59 62 return self::REJECTED;
60 63 }
61 - public function resolve($value)
64 + public function resolve($value) : void
62 65 {
63 - throw new \LogicException("Cannot resolve a rejected promise");
66 + throw new \LogicException('Cannot resolve a rejected promise');
64 67 }
65 - public function reject($reason)
68 + public function reject($reason) : void
66 69 {
67 70 if ($reason !== $this->reason) {
68 - throw new \LogicException("Cannot reject a rejected promise");
71 + throw new \LogicException('Cannot reject a rejected promise');
69 72 }
70 73 }
71 - public function cancel()
74 + public function cancel() : void
72 75 {
73 76 // pass
74 77 }
75 78 }