summaryrefslogtreecommitdiff
path: root/vendor/guzzlehttp/promises/src/Utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzlehttp/promises/src/Utils.php')
-rw-r--r--vendor/guzzlehttp/promises/src/Utils.php69
1 files changed, 26 insertions, 43 deletions
diff --git a/vendor/guzzlehttp/promises/src/Utils.php b/vendor/guzzlehttp/promises/src/Utils.php
index 8647126..e1570d7 100644
--- a/vendor/guzzlehttp/promises/src/Utils.php
+++ b/vendor/guzzlehttp/promises/src/Utils.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
namespace GuzzleHttp\Promise;
final class Utils
@@ -17,11 +19,9 @@ final class Utils
* }
* </code>
*
- * @param TaskQueueInterface $assign Optionally specify a new queue instance.
- *
- * @return TaskQueueInterface
+ * @param TaskQueueInterface|null $assign Optionally specify a new queue instance.
*/
- public static function queue(TaskQueueInterface $assign = null)
+ public static function queue(TaskQueueInterface $assign = null): TaskQueueInterface
{
static $queue;
@@ -39,22 +39,18 @@ final class Utils
* returns a promise that is fulfilled or rejected with the result.
*
* @param callable $task Task function to run.
- *
- * @return PromiseInterface
*/
- public static function task(callable $task)
+ public static function task(callable $task): PromiseInterface
{
$queue = self::queue();
$promise = new Promise([$queue, 'run']);
- $queue->add(function () use ($task, $promise) {
+ $queue->add(function () use ($task, $promise): void {
try {
if (Is::pending($promise)) {
$promise->resolve($task());
}
} catch (\Throwable $e) {
$promise->reject($e);
- } catch (\Exception $e) {
- $promise->reject($e);
}
});
@@ -72,22 +68,18 @@ final class Utils
* key mapping to the rejection reason of the promise.
*
* @param PromiseInterface $promise Promise or value.
- *
- * @return array
*/
- public static function inspect(PromiseInterface $promise)
+ public static function inspect(PromiseInterface $promise): array
{
try {
return [
'state' => PromiseInterface::FULFILLED,
- 'value' => $promise->wait()
+ 'value' => $promise->wait(),
];
} catch (RejectionException $e) {
return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()];
} catch (\Throwable $e) {
return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
- } catch (\Exception $e) {
- return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
}
}
@@ -100,14 +92,12 @@ final class Utils
* @see inspect for the inspection state array format.
*
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
- *
- * @return array
*/
- public static function inspectAll($promises)
+ public static function inspectAll($promises): array
{
$results = [];
foreach ($promises as $key => $promise) {
- $results[$key] = inspect($promise);
+ $results[$key] = self::inspect($promise);
}
return $results;
@@ -122,12 +112,9 @@ final class Utils
*
* @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
*
- * @return array
- *
- * @throws \Exception on error
- * @throws \Throwable on error in PHP >=7
+ * @throws \Throwable on error
*/
- public static function unwrap($promises)
+ public static function unwrap($promises): array
{
$results = [];
foreach ($promises as $key => $promise) {
@@ -147,22 +134,21 @@ final class Utils
*
* @param mixed $promises Promises or values.
* @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
- *
- * @return PromiseInterface
*/
- public static function all($promises, $recursive = false)
+ public static function all($promises, bool $recursive = false): PromiseInterface
{
$results = [];
$promise = Each::of(
$promises,
- function ($value, $idx) use (&$results) {
+ function ($value, $idx) use (&$results): void {
$results[$idx] = $value;
},
- function ($reason, $idx, Promise $aggregate) {
+ function ($reason, $idx, Promise $aggregate): void {
$aggregate->reject($reason);
}
)->then(function () use (&$results) {
ksort($results);
+
return $results;
});
@@ -173,6 +159,7 @@ final class Utils
return self::all($promises, $recursive);
}
}
+
return $results;
});
}
@@ -193,17 +180,15 @@ final class Utils
*
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
- *
- * @return PromiseInterface
*/
- public static function some($count, $promises)
+ public static function some(int $count, $promises): PromiseInterface
{
$results = [];
$rejections = [];
return Each::of(
$promises,
- function ($value, $idx, PromiseInterface $p) use (&$results, $count) {
+ function ($value, $idx, PromiseInterface $p) use (&$results, $count): void {
if (Is::settled($p)) {
return;
}
@@ -212,7 +197,7 @@ final class Utils
$p->resolve(null);
}
},
- function ($reason) use (&$rejections) {
+ function ($reason) use (&$rejections): void {
$rejections[] = $reason;
}
)->then(
@@ -224,6 +209,7 @@ final class Utils
);
}
ksort($results);
+
return array_values($results);
}
);
@@ -234,10 +220,8 @@ final class Utils
* fulfillment value is not an array of 1 but the value directly.
*
* @param mixed $promises Promises or values.
- *
- * @return PromiseInterface
*/
- public static function any($promises)
+ public static function any($promises): PromiseInterface
{
return self::some(1, $promises)->then(function ($values) {
return $values[0];
@@ -253,23 +237,22 @@ final class Utils
* @see inspect for the inspection state array format.
*
* @param mixed $promises Promises or values.
- *
- * @return PromiseInterface
*/
- public static function settle($promises)
+ public static function settle($promises): PromiseInterface
{
$results = [];
return Each::of(
$promises,
- function ($value, $idx) use (&$results) {
+ function ($value, $idx) use (&$results): void {
$results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value];
},
- function ($reason, $idx) use (&$results) {
+ function ($reason, $idx) use (&$results): void {
$results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason];
}
)->then(function () use (&$results) {
ksort($results);
+
return $results;
});
}