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/google/guzzlehttp/promises/src/Promise.php +17 -17 1.2.7 → 1.4.2 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 declare (strict_types=1);
4 -namespace Dudlewebs\WPMCS\GuzzleHttp\Promise;
4 +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise;
5 5
6 6 /**
7 7 * Promises/A+ implementation that avoids recursion when possible.
8 8 *
@@ -26,9 +26,9 @@
26 26 {
27 27 $this->waitFn = $waitFn;
28 28 $this->cancelFn = $cancelFn;
29 29 }
30 - public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface
30 + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface
31 31 {
32 32 if ($this->state === self::PENDING) {
33 33 $p = new Promise(null, [$this, 'cancel']);
34 34 $this->handlers[] = [$p, $onFulfilled, $onRejected];
@@ -45,9 +45,9 @@
45 45 // and immediately invoke any callbacks.
46 46 $rejection = Create::rejectionFor($this->result);
47 47 return $onRejected ? $rejection->then(null, $onRejected) : $rejection;
48 48 }
49 - public function otherwise(callable $onRejected): PromiseInterface
49 + public function otherwise(callable $onRejected) : PromiseInterface
50 50 {
51 51 return $this->then(null, $onRejected);
52 52 }
53 53 public function wait(bool $unwrap = \true)
@@ -63,13 +63,13 @@
63 63 // It's rejected so "unwrap" and throw an exception.
64 64 throw Create::exceptionFor($this->result);
65 65 }
66 66 }
67 - public function getState(): string
67 + public function getState() : string
68 68 {
69 69 return $this->state;
70 70 }
71 - public function cancel(): void
71 + public function cancel() : void
72 72 {
73 73 if ($this->state !== self::PENDING) {
74 74 return;
75 75 }
@@ -88,17 +88,17 @@
88 88 if ($this->state === self::PENDING) {
89 89 $this->reject(new CancellationException('Promise has been cancelled'));
90 90 }
91 91 }
92 - public function resolve($value): void
92 + public function resolve($value) : void
93 93 {
94 94 $this->settle(self::FULFILLED, $value);
95 95 }
96 - public function reject($reason): void
96 + public function reject($reason) : void
97 97 {
98 98 $this->settle(self::REJECTED, $reason);
99 99 }
100 - private function settle(string $state, $value): void
100 + private function settle(string $state, $value) : void
101 101 {
102 102 if ($this->state !== self::PENDING) {
103 103 // Ignore calls with the same resolution.
104 104 if ($state === $this->state && $value === $this->result) {
@@ -120,12 +120,12 @@
120 120 return;
121 121 }
122 122 // If the value was not a settled promise or a thenable, then resolve
123 123 // it in the task queue using the correct ID.
124 - if (!is_object($value) || !method_exists($value, 'then')) {
124 + if (!\is_object($value) || !\method_exists($value, 'then')) {
125 125 $id = $state === self::FULFILLED ? 1 : 2;
126 126 // It's a success, so resolve the handlers in the queue.
127 - Utils::queue()->add(static function () use ($id, $value, $handlers): void {
127 + Utils::queue()->add(static function () use($id, $value, $handlers) : void {
128 128 foreach ($handlers as $handler) {
129 129 self::callHandler($id, $value, $handler);
130 130 }
131 131 });
@@ -130,16 +130,16 @@
130 130 }
131 131 });
132 132 } elseif ($value instanceof Promise && Is::pending($value)) {
133 133 // We can just merge our handlers onto the next promise.
134 - $value->handlers = array_merge($value->handlers, $handlers);
134 + $value->handlers = \array_merge($value->handlers, $handlers);
135 135 } else {
136 136 // Resolve the handlers when the forwarded promise is resolved.
137 - $value->then(static function ($value) use ($handlers): void {
137 + $value->then(static function ($value) use($handlers) : void {
138 138 foreach ($handlers as $handler) {
139 139 self::callHandler(1, $value, $handler);
140 140 }
141 - }, static function ($reason) use ($handlers): void {
141 + }, static function ($reason) use($handlers) : void {
142 142 foreach ($handlers as $handler) {
143 143 self::callHandler(2, $reason, $handler);
144 144 }
145 145 });
@@ -151,9 +151,9 @@
151 151 * @param int $index 1 (resolve) or 2 (reject).
152 152 * @param mixed $value Value to pass to the callback.
153 153 * @param array $handler Array of handler data (promise and callbacks).
154 154 */
155 - private static function callHandler(int $index, $value, array $handler): void
155 + private static function callHandler(int $index, $value, array $handler) : void
156 156 {
157 157 /** @var PromiseInterface $promise */
158 158 $promise = $handler[0];
159 159 // The promise may have been cancelled or resolved before placing
@@ -182,9 +182,9 @@
182 182 } catch (\Throwable $reason) {
183 183 $promise->reject($reason);
184 184 }
185 185 }
186 - private function waitIfPending(): void
186 + private function waitIfPending() : void
187 187 {
188 188 if ($this->state !== self::PENDING) {
189 189 return;
190 190 } elseif ($this->waitFn) {
@@ -200,9 +200,9 @@
200 200 if ($this->state === self::PENDING) {
201 201 $this->reject('Invoking the wait callback did not resolve the promise');
202 202 }
203 203 }
204 - private function invokeWaitFn(): void
204 + private function invokeWaitFn() : void
205 205 {
206 206 try {
207 207 $wfn = $this->waitFn;
208 208 $this->waitFn = null;
@@ -218,9 +218,9 @@
218 218 throw $reason;
219 219 }
220 220 }
221 221 }
222 - private function invokeWaitList(): void
222 + private function invokeWaitList() : void
223 223 {
224 224 $waitList = $this->waitList;
225 225 $this->waitList = null;
226 226 foreach ($waitList as $result) {