Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../vendor_p.../guzzleht.../promises/src
File: EachPromise.php
<?php
[0] Fix | Delete
[1] Fix | Delete
declare (strict_types=1);
[2] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp\Promise;
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* Represents a promise that iterates over many promises and invokes
[6] Fix | Delete
* side-effect functions in the process.
[7] Fix | Delete
*
[8] Fix | Delete
* @final
[9] Fix | Delete
*/
[10] Fix | Delete
class EachPromise implements \YoastSEO_Vendor\GuzzleHttp\Promise\PromisorInterface
[11] Fix | Delete
{
[12] Fix | Delete
private $pending = [];
[13] Fix | Delete
private $nextPendingIndex = 0;
[14] Fix | Delete
/** @var \Iterator|null */
[15] Fix | Delete
private $iterable;
[16] Fix | Delete
/** @var callable|int|null */
[17] Fix | Delete
private $concurrency;
[18] Fix | Delete
/** @var callable|null */
[19] Fix | Delete
private $onFulfilled;
[20] Fix | Delete
/** @var callable|null */
[21] Fix | Delete
private $onRejected;
[22] Fix | Delete
/** @var Promise|null */
[23] Fix | Delete
private $aggregate;
[24] Fix | Delete
/** @var bool|null */
[25] Fix | Delete
private $mutex;
[26] Fix | Delete
/**
[27] Fix | Delete
* Configuration hash can include the following key value pairs:
[28] Fix | Delete
*
[29] Fix | Delete
* - fulfilled: (callable) Invoked when a promise fulfills. The function
[30] Fix | Delete
* is invoked with three arguments: the fulfillment value, the index
[31] Fix | Delete
* position from the iterable list of the promise, and the aggregate
[32] Fix | Delete
* promise that manages all of the promises. The aggregate promise may
[33] Fix | Delete
* be resolved from within the callback to short-circuit the promise.
[34] Fix | Delete
* - rejected: (callable) Invoked when a promise is rejected. The
[35] Fix | Delete
* function is invoked with three arguments: the rejection reason, the
[36] Fix | Delete
* index position from the iterable list of the promise, and the
[37] Fix | Delete
* aggregate promise that manages all of the promises. The aggregate
[38] Fix | Delete
* promise may be resolved from within the callback to short-circuit
[39] Fix | Delete
* the promise.
[40] Fix | Delete
* - concurrency: (integer) Pass this configuration option to limit the
[41] Fix | Delete
* allowed number of outstanding concurrently executing promises,
[42] Fix | Delete
* creating a capped pool of promises. There is no limit by default.
[43] Fix | Delete
*
[44] Fix | Delete
* @param mixed $iterable Promises or values to iterate.
[45] Fix | Delete
* @param array $config Configuration options
[46] Fix | Delete
*/
[47] Fix | Delete
public function __construct($iterable, array $config = [])
[48] Fix | Delete
{
[49] Fix | Delete
$this->iterable = \YoastSEO_Vendor\GuzzleHttp\Promise\Create::iterFor($iterable);
[50] Fix | Delete
if (isset($config['concurrency'])) {
[51] Fix | Delete
$this->concurrency = $config['concurrency'];
[52] Fix | Delete
}
[53] Fix | Delete
if (isset($config['fulfilled'])) {
[54] Fix | Delete
$this->onFulfilled = $config['fulfilled'];
[55] Fix | Delete
}
[56] Fix | Delete
if (isset($config['rejected'])) {
[57] Fix | Delete
$this->onRejected = $config['rejected'];
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
/** @psalm-suppress InvalidNullableReturnType */
[61] Fix | Delete
public function promise() : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
[62] Fix | Delete
{
[63] Fix | Delete
if ($this->aggregate) {
[64] Fix | Delete
return $this->aggregate;
[65] Fix | Delete
}
[66] Fix | Delete
try {
[67] Fix | Delete
$this->createPromise();
[68] Fix | Delete
/** @psalm-assert Promise $this->aggregate */
[69] Fix | Delete
$this->iterable->rewind();
[70] Fix | Delete
$this->refillPending();
[71] Fix | Delete
} catch (\Throwable $e) {
[72] Fix | Delete
$this->aggregate->reject($e);
[73] Fix | Delete
}
[74] Fix | Delete
/**
[75] Fix | Delete
* @psalm-suppress NullableReturnStatement
[76] Fix | Delete
*/
[77] Fix | Delete
return $this->aggregate;
[78] Fix | Delete
}
[79] Fix | Delete
private function createPromise() : void
[80] Fix | Delete
{
[81] Fix | Delete
$this->mutex = \false;
[82] Fix | Delete
$this->aggregate = new \YoastSEO_Vendor\GuzzleHttp\Promise\Promise(function () : void {
[83] Fix | Delete
if ($this->checkIfFinished()) {
[84] Fix | Delete
return;
[85] Fix | Delete
}
[86] Fix | Delete
\reset($this->pending);
[87] Fix | Delete
// Consume a potentially fluctuating list of promises while
[88] Fix | Delete
// ensuring that indexes are maintained (precluding array_shift).
[89] Fix | Delete
while ($promise = \current($this->pending)) {
[90] Fix | Delete
\next($this->pending);
[91] Fix | Delete
$promise->wait();
[92] Fix | Delete
if (\YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($this->aggregate)) {
[93] Fix | Delete
return;
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
});
[97] Fix | Delete
// Clear the references when the promise is resolved.
[98] Fix | Delete
$clearFn = function () : void {
[99] Fix | Delete
$this->iterable = $this->concurrency = $this->pending = null;
[100] Fix | Delete
$this->onFulfilled = $this->onRejected = null;
[101] Fix | Delete
$this->nextPendingIndex = 0;
[102] Fix | Delete
};
[103] Fix | Delete
$this->aggregate->then($clearFn, $clearFn);
[104] Fix | Delete
}
[105] Fix | Delete
private function refillPending() : void
[106] Fix | Delete
{
[107] Fix | Delete
if (!$this->concurrency) {
[108] Fix | Delete
// Add all pending promises.
[109] Fix | Delete
while ($this->addPending() && $this->advanceIterator()) {
[110] Fix | Delete
}
[111] Fix | Delete
return;
[112] Fix | Delete
}
[113] Fix | Delete
// Add only up to N pending promises.
[114] Fix | Delete
$concurrency = \is_callable($this->concurrency) ? ($this->concurrency)(\count($this->pending)) : $this->concurrency;
[115] Fix | Delete
$concurrency = \max($concurrency - \count($this->pending), 0);
[116] Fix | Delete
// Concurrency may be set to 0 to disallow new promises.
[117] Fix | Delete
if (!$concurrency) {
[118] Fix | Delete
return;
[119] Fix | Delete
}
[120] Fix | Delete
// Add the first pending promise.
[121] Fix | Delete
$this->addPending();
[122] Fix | Delete
// Note this is special handling for concurrency=1 so that we do
[123] Fix | Delete
// not advance the iterator after adding the first promise. This
[124] Fix | Delete
// helps work around issues with generators that might not have the
[125] Fix | Delete
// next value to yield until promise callbacks are called.
[126] Fix | Delete
while (--$concurrency && $this->advanceIterator() && $this->addPending()) {
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
private function addPending() : bool
[130] Fix | Delete
{
[131] Fix | Delete
if (!$this->iterable || !$this->iterable->valid()) {
[132] Fix | Delete
return \false;
[133] Fix | Delete
}
[134] Fix | Delete
$promise = \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($this->iterable->current());
[135] Fix | Delete
$key = $this->iterable->key();
[136] Fix | Delete
// Iterable keys may not be unique, so we use a counter to
[137] Fix | Delete
// guarantee uniqueness
[138] Fix | Delete
$idx = $this->nextPendingIndex++;
[139] Fix | Delete
$this->pending[$idx] = $promise->then(function ($value) use($idx, $key) : void {
[140] Fix | Delete
if ($this->onFulfilled) {
[141] Fix | Delete
($this->onFulfilled)($value, $key, $this->aggregate);
[142] Fix | Delete
}
[143] Fix | Delete
$this->step($idx);
[144] Fix | Delete
}, function ($reason) use($idx, $key) : void {
[145] Fix | Delete
if ($this->onRejected) {
[146] Fix | Delete
($this->onRejected)($reason, $key, $this->aggregate);
[147] Fix | Delete
}
[148] Fix | Delete
$this->step($idx);
[149] Fix | Delete
});
[150] Fix | Delete
return \true;
[151] Fix | Delete
}
[152] Fix | Delete
private function advanceIterator() : bool
[153] Fix | Delete
{
[154] Fix | Delete
// Place a lock on the iterator so that we ensure to not recurse,
[155] Fix | Delete
// preventing fatal generator errors.
[156] Fix | Delete
if ($this->mutex) {
[157] Fix | Delete
return \false;
[158] Fix | Delete
}
[159] Fix | Delete
$this->mutex = \true;
[160] Fix | Delete
try {
[161] Fix | Delete
$this->iterable->next();
[162] Fix | Delete
$this->mutex = \false;
[163] Fix | Delete
return \true;
[164] Fix | Delete
} catch (\Throwable $e) {
[165] Fix | Delete
$this->aggregate->reject($e);
[166] Fix | Delete
$this->mutex = \false;
[167] Fix | Delete
return \false;
[168] Fix | Delete
}
[169] Fix | Delete
}
[170] Fix | Delete
private function step(int $idx) : void
[171] Fix | Delete
{
[172] Fix | Delete
// If the promise was already resolved, then ignore this step.
[173] Fix | Delete
if (\YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($this->aggregate)) {
[174] Fix | Delete
return;
[175] Fix | Delete
}
[176] Fix | Delete
unset($this->pending[$idx]);
[177] Fix | Delete
// Only refill pending promises if we are not locked, preventing the
[178] Fix | Delete
// EachPromise to recursively invoke the provided iterator, which
[179] Fix | Delete
// cause a fatal error: "Cannot resume an already running generator"
[180] Fix | Delete
if ($this->advanceIterator() && !$this->checkIfFinished()) {
[181] Fix | Delete
// Add more pending promises if possible.
[182] Fix | Delete
$this->refillPending();
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
private function checkIfFinished() : bool
[186] Fix | Delete
{
[187] Fix | Delete
if (!$this->pending && !$this->iterable->valid()) {
[188] Fix | Delete
// Resolve the promise if there's nothing left to do.
[189] Fix | Delete
$this->aggregate->resolve(null);
[190] Fix | Delete
return \true;
[191] Fix | Delete
}
[192] Fix | Delete
return \false;
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function