| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace Dudlewebs\WPMCS\s3\Aws; |
| 4 | 4 | |
| 5 | 5 | use Dudlewebs\WPMCS\s3\Aws\Exception\AwsException; |
| 6 | 6 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\Coroutine; |
| 7 | +use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\PromiseInterface; | |
| 7 | 8 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\PromisorInterface; |
| 8 | 9 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\RejectedPromise; |
| 9 | 10 | /** |
| 10 | 11 | * "Waiters" are associated with an AWS resource (e.g., EC2 instance), and poll |
| @@ -61,13 +62,14 @@ | ||
| 61 | 62 | } |
| 62 | 63 | if ($this->config['before'] && !\is_callable($this->config['before'])) { |
| 63 | 64 | throw new \InvalidArgumentException('The provided "before" callback is not callable.'); |
| 64 | 65 | } |
| 66 | + MetricsBuilder::appendMetricsCaptureMiddleware($this->client->getHandlerList(), MetricsBuilder::WAITER); | |
| 65 | 67 | } |
| 66 | 68 | /** |
| 67 | 69 | * @return Coroutine |
| 68 | 70 | */ |
| 69 | - public function promise() | |
| 71 | + public function promise() : PromiseInterface | |
| 70 | 72 | { |
| 71 | 73 | return Coroutine::of(function () { |
| 72 | 74 | $name = $this->config['operation']; |
| 73 | 75 | for ($state = 'retry', $attempt = 1; $state === 'retry'; $attempt++) { |
| @@ -147,9 +149,9 @@ | ||
| 147 | 149 | * @return bool |
| 148 | 150 | */ |
| 149 | 151 | private function matchesPath($result, array $acceptor) |
| 150 | 152 | { |
| 151 | - return !$result instanceof ResultInterface ? \false : $acceptor['expected'] == $result->search($acceptor['argument']); | |
| 153 | + return $result instanceof ResultInterface && $acceptor['expected'] === $result->search($acceptor['argument']); | |
| 152 | 154 | } |
| 153 | 155 | /** |
| 154 | 156 | * @param Result $result Result or exception. |
| 155 | 157 | * @param array $acceptor Acceptor configuration being checked. |
| @@ -161,8 +163,12 @@ | ||
| 161 | 163 | if (!$result instanceof ResultInterface) { |
| 162 | 164 | return \false; |
| 163 | 165 | } |
| 164 | 166 | $actuals = $result->search($acceptor['argument']) ?: []; |
| 167 | + // If is empty or not evaluates to an array it must return false. | |
| 168 | + if (empty($actuals) || !\is_array($actuals)) { | |
| 169 | + return \false; | |
| 170 | + } | |
| 165 | 171 | foreach ($actuals as $actual) { |
| 166 | 172 | if ($actual != $acceptor['expected']) { |
| 167 | 173 | return \false; |
| 168 | 174 | } |
| @@ -180,8 +186,12 @@ | ||
| 180 | 186 | if (!$result instanceof ResultInterface) { |
| 181 | 187 | return \false; |
| 182 | 188 | } |
| 183 | 189 | $actuals = $result->search($acceptor['argument']) ?: []; |
| 190 | + // If is empty or not evaluates to an array it must return false. | |
| 191 | + if (empty($actuals) || !\is_array($actuals)) { | |
| 192 | + return \false; | |
| 193 | + } | |
| 184 | 194 | return \in_array($acceptor['expected'], $actuals); |
| 185 | 195 | } |
| 186 | 196 | /** |
| 187 | 197 | * @param Result $result Result or exception. |
| @@ -206,8 +216,13 @@ | ||
| 206 | 216 | * @return bool |
| 207 | 217 | */ |
| 208 | 218 | private function matchesError($result, array $acceptor) |
| 209 | 219 | { |
| 220 | + // If expected is true then the $result should be an instance of | |
| 221 | + // AwsException, otherwise it should not. | |
| 222 | + if (isset($acceptor['expected']) && \is_bool($acceptor['expected'])) { | |
| 223 | + return $acceptor['expected'] === $result instanceof AwsException; | |
| 224 | + } | |
| 210 | 225 | if ($result instanceof AwsException) { |
| 211 | 226 | return $result->isConnectionError() || $result->getAwsErrorCode() == $acceptor['expected']; |
| 212 | 227 | } |
| 213 | 228 | return \false; |