← All changes
|
includes/sdk/google/guzzlehttp/promises/src/EachPromise.php
+17
-17
1.2.13
→
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 | * Represents a promise that iterates over many promises and invokes |
| 8 | 8 | * side-effect functions in the process. |
| @@ -59,9 +59,9 @@ | ||
| 59 | 59 | $this->onRejected = $config['rejected']; |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | /** @psalm-suppress InvalidNullableReturnType */ |
| 63 | - public function promise(): PromiseInterface | |
| 63 | + public function promise() : PromiseInterface | |
| 64 | 64 | { |
| 65 | 65 | if ($this->aggregate) { |
| 66 | 66 | return $this->aggregate; |
| 67 | 67 | } |
| @@ -77,20 +77,20 @@ | ||
| 77 | 77 | * @psalm-suppress NullableReturnStatement |
| 78 | 78 | */ |
| 79 | 79 | return $this->aggregate; |
| 80 | 80 | } |
| 81 | - private function createPromise(): void | |
| 81 | + private function createPromise() : void | |
| 82 | 82 | { |
| 83 | 83 | $this->mutex = \false; |
| 84 | - $this->aggregate = new Promise(function (): void { | |
| 84 | + $this->aggregate = new Promise(function () : void { | |
| 85 | 85 | if ($this->checkIfFinished()) { |
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | - reset($this->pending); | |
| 88 | + \reset($this->pending); | |
| 89 | 89 | // Consume a potentially fluctuating list of promises while |
| 90 | 90 | // ensuring that indexes are maintained (precluding array_shift). |
| 91 | - while ($promise = current($this->pending)) { | |
| 92 | - next($this->pending); | |
| 91 | + while ($promise = \current($this->pending)) { | |
| 92 | + \next($this->pending); | |
| 93 | 93 | $promise->wait(); |
| 94 | 94 | if (Is::settled($this->aggregate)) { |
| 95 | 95 | return; |
| 96 | 96 | } |
| @@ -96,9 +96,9 @@ | ||
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | }); |
| 99 | 99 | // Clear the references when the promise is resolved. |
| 100 | - $clearFn = function (): void { | |
| 100 | + $clearFn = function () : void { | |
| 101 | 101 | $this->iterable = $this->concurrency = $this->pending = null; |
| 102 | 102 | $this->onFulfilled = $this->onRejected = null; |
| 103 | 103 | $this->nextPendingIndex = 0; |
| 104 | 104 | }; |
| @@ -103,9 +103,9 @@ | ||
| 103 | 103 | $this->nextPendingIndex = 0; |
| 104 | 104 | }; |
| 105 | 105 | $this->aggregate->then($clearFn, $clearFn); |
| 106 | 106 | } |
| 107 | - private function refillPending(): void | |
| 107 | + private function refillPending() : void | |
| 108 | 108 | { |
| 109 | 109 | if (!$this->concurrency) { |
| 110 | 110 | // Add all pending promises. |
| 111 | 111 | while ($this->addPending() && $this->advanceIterator()) { |
| @@ -112,10 +112,10 @@ | ||
| 112 | 112 | } |
| 113 | 113 | return; |
| 114 | 114 | } |
| 115 | 115 | // Add only up to N pending promises. |
| 116 | - $concurrency = is_callable($this->concurrency) ? ($this->concurrency)(count($this->pending)) : $this->concurrency; | |
| 117 | - $concurrency = max($concurrency - count($this->pending), 0); | |
| 116 | + $concurrency = \is_callable($this->concurrency) ? ($this->concurrency)(\count($this->pending)) : $this->concurrency; | |
| 117 | + $concurrency = \max($concurrency - \count($this->pending), 0); | |
| 118 | 118 | // Concurrency may be set to 0 to disallow new promises. |
| 119 | 119 | if (!$concurrency) { |
| 120 | 120 | return; |
| 121 | 121 | } |
| @@ -127,9 +127,9 @@ | ||
| 127 | 127 | // next value to yield until promise callbacks are called. |
| 128 | 128 | while (--$concurrency && $this->advanceIterator() && $this->addPending()) { |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | - private function addPending(): bool | |
| 131 | + private function addPending() : bool | |
| 132 | 132 | { |
| 133 | 133 | if (!$this->iterable || !$this->iterable->valid()) { |
| 134 | 134 | return \false; |
| 135 | 135 | } |
| @@ -137,14 +137,14 @@ | ||
| 137 | 137 | $key = $this->iterable->key(); |
| 138 | 138 | // Iterable keys may not be unique, so we use a counter to |
| 139 | 139 | // guarantee uniqueness |
| 140 | 140 | $idx = $this->nextPendingIndex++; |
| 141 | - $this->pending[$idx] = $promise->then(function ($value) use ($idx, $key): void { | |
| 141 | + $this->pending[$idx] = $promise->then(function ($value) use($idx, $key) : void { | |
| 142 | 142 | if ($this->onFulfilled) { |
| 143 | 143 | ($this->onFulfilled)($value, $key, $this->aggregate); |
| 144 | 144 | } |
| 145 | 145 | $this->step($idx); |
| 146 | - }, function ($reason) use ($idx, $key): void { | |
| 146 | + }, function ($reason) use($idx, $key) : void { | |
| 147 | 147 | if ($this->onRejected) { |
| 148 | 148 | ($this->onRejected)($reason, $key, $this->aggregate); |
| 149 | 149 | } |
| 150 | 150 | $this->step($idx); |
| @@ -150,9 +150,9 @@ | ||
| 150 | 150 | $this->step($idx); |
| 151 | 151 | }); |
| 152 | 152 | return \true; |
| 153 | 153 | } |
| 154 | - private function advanceIterator(): bool | |
| 154 | + private function advanceIterator() : bool | |
| 155 | 155 | { |
| 156 | 156 | // Place a lock on the iterator so that we ensure to not recurse, |
| 157 | 157 | // preventing fatal generator errors. |
| 158 | 158 | if ($this->mutex) { |
| @@ -168,9 +168,9 @@ | ||
| 168 | 168 | $this->mutex = \false; |
| 169 | 169 | return \false; |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | - private function step(int $idx): void | |
| 172 | + private function step(int $idx) : void | |
| 173 | 173 | { |
| 174 | 174 | // If the promise was already resolved, then ignore this step. |
| 175 | 175 | if (Is::settled($this->aggregate)) { |
| 176 | 176 | return; |
| @@ -183,9 +183,9 @@ | ||
| 183 | 183 | // Add more pending promises if possible. |
| 184 | 184 | $this->refillPending(); |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | - private function checkIfFinished(): bool | |
| 187 | + private function checkIfFinished() : bool | |
| 188 | 188 | { |
| 189 | 189 | if (!$this->pending && !$this->iterable->valid()) { |
| 190 | 190 | // Resolve the promise if there's nothing left to do. |
| 191 | 191 | $this->aggregate->resolve(null); |