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: Promise.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
* Promises/A+ implementation that avoids recursion when possible.
[6] Fix | Delete
*
[7] Fix | Delete
* @see https://promisesaplus.com/
[8] Fix | Delete
*
[9] Fix | Delete
* @final
[10] Fix | Delete
*/
[11] Fix | Delete
class Promise implements \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
[12] Fix | Delete
{
[13] Fix | Delete
private $state = self::PENDING;
[14] Fix | Delete
private $result;
[15] Fix | Delete
private $cancelFn;
[16] Fix | Delete
private $waitFn;
[17] Fix | Delete
private $waitList;
[18] Fix | Delete
private $handlers = [];
[19] Fix | Delete
/**
[20] Fix | Delete
* @param callable $waitFn Fn that when invoked resolves the promise.
[21] Fix | Delete
* @param callable $cancelFn Fn that when invoked cancels the promise.
[22] Fix | Delete
*/
[23] Fix | Delete
public function __construct(callable $waitFn = null, callable $cancelFn = null)
[24] Fix | Delete
{
[25] Fix | Delete
$this->waitFn = $waitFn;
[26] Fix | Delete
$this->cancelFn = $cancelFn;
[27] Fix | Delete
}
[28] Fix | Delete
public function then(callable $onFulfilled = null, callable $onRejected = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
[29] Fix | Delete
{
[30] Fix | Delete
if ($this->state === self::PENDING) {
[31] Fix | Delete
$p = new \YoastSEO_Vendor\GuzzleHttp\Promise\Promise(null, [$this, 'cancel']);
[32] Fix | Delete
$this->handlers[] = [$p, $onFulfilled, $onRejected];
[33] Fix | Delete
$p->waitList = $this->waitList;
[34] Fix | Delete
$p->waitList[] = $this;
[35] Fix | Delete
return $p;
[36] Fix | Delete
}
[37] Fix | Delete
// Return a fulfilled promise and immediately invoke any callbacks.
[38] Fix | Delete
if ($this->state === self::FULFILLED) {
[39] Fix | Delete
$promise = \YoastSEO_Vendor\GuzzleHttp\Promise\Create::promiseFor($this->result);
[40] Fix | Delete
return $onFulfilled ? $promise->then($onFulfilled) : $promise;
[41] Fix | Delete
}
[42] Fix | Delete
// It's either cancelled or rejected, so return a rejected promise
[43] Fix | Delete
// and immediately invoke any callbacks.
[44] Fix | Delete
$rejection = \YoastSEO_Vendor\GuzzleHttp\Promise\Create::rejectionFor($this->result);
[45] Fix | Delete
return $onRejected ? $rejection->then(null, $onRejected) : $rejection;
[46] Fix | Delete
}
[47] Fix | Delete
public function otherwise(callable $onRejected) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
[48] Fix | Delete
{
[49] Fix | Delete
return $this->then(null, $onRejected);
[50] Fix | Delete
}
[51] Fix | Delete
public function wait(bool $unwrap = \true)
[52] Fix | Delete
{
[53] Fix | Delete
$this->waitIfPending();
[54] Fix | Delete
if ($this->result instanceof \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface) {
[55] Fix | Delete
return $this->result->wait($unwrap);
[56] Fix | Delete
}
[57] Fix | Delete
if ($unwrap) {
[58] Fix | Delete
if ($this->state === self::FULFILLED) {
[59] Fix | Delete
return $this->result;
[60] Fix | Delete
}
[61] Fix | Delete
// It's rejected so "unwrap" and throw an exception.
[62] Fix | Delete
throw \YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($this->result);
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
public function getState() : string
[66] Fix | Delete
{
[67] Fix | Delete
return $this->state;
[68] Fix | Delete
}
[69] Fix | Delete
public function cancel() : void
[70] Fix | Delete
{
[71] Fix | Delete
if ($this->state !== self::PENDING) {
[72] Fix | Delete
return;
[73] Fix | Delete
}
[74] Fix | Delete
$this->waitFn = $this->waitList = null;
[75] Fix | Delete
if ($this->cancelFn) {
[76] Fix | Delete
$fn = $this->cancelFn;
[77] Fix | Delete
$this->cancelFn = null;
[78] Fix | Delete
try {
[79] Fix | Delete
$fn();
[80] Fix | Delete
} catch (\Throwable $e) {
[81] Fix | Delete
$this->reject($e);
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
// Reject the promise only if it wasn't rejected in a then callback.
[85] Fix | Delete
/** @psalm-suppress RedundantCondition */
[86] Fix | Delete
if ($this->state === self::PENDING) {
[87] Fix | Delete
$this->reject(new \YoastSEO_Vendor\GuzzleHttp\Promise\CancellationException('Promise has been cancelled'));
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
public function resolve($value) : void
[91] Fix | Delete
{
[92] Fix | Delete
$this->settle(self::FULFILLED, $value);
[93] Fix | Delete
}
[94] Fix | Delete
public function reject($reason) : void
[95] Fix | Delete
{
[96] Fix | Delete
$this->settle(self::REJECTED, $reason);
[97] Fix | Delete
}
[98] Fix | Delete
private function settle(string $state, $value) : void
[99] Fix | Delete
{
[100] Fix | Delete
if ($this->state !== self::PENDING) {
[101] Fix | Delete
// Ignore calls with the same resolution.
[102] Fix | Delete
if ($state === $this->state && $value === $this->result) {
[103] Fix | Delete
return;
[104] Fix | Delete
}
[105] Fix | Delete
throw $this->state === $state ? new \LogicException("The promise is already {$state}.") : new \LogicException("Cannot change a {$this->state} promise to {$state}");
[106] Fix | Delete
}
[107] Fix | Delete
if ($value === $this) {
[108] Fix | Delete
throw new \LogicException('Cannot fulfill or reject a promise with itself');
[109] Fix | Delete
}
[110] Fix | Delete
// Clear out the state of the promise but stash the handlers.
[111] Fix | Delete
$this->state = $state;
[112] Fix | Delete
$this->result = $value;
[113] Fix | Delete
$handlers = $this->handlers;
[114] Fix | Delete
$this->handlers = null;
[115] Fix | Delete
$this->waitList = $this->waitFn = null;
[116] Fix | Delete
$this->cancelFn = null;
[117] Fix | Delete
if (!$handlers) {
[118] Fix | Delete
return;
[119] Fix | Delete
}
[120] Fix | Delete
// If the value was not a settled promise or a thenable, then resolve
[121] Fix | Delete
// it in the task queue using the correct ID.
[122] Fix | Delete
if (!\is_object($value) || !\method_exists($value, 'then')) {
[123] Fix | Delete
$id = $state === self::FULFILLED ? 1 : 2;
[124] Fix | Delete
// It's a success, so resolve the handlers in the queue.
[125] Fix | Delete
\YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue()->add(static function () use($id, $value, $handlers) : void {
[126] Fix | Delete
foreach ($handlers as $handler) {
[127] Fix | Delete
self::callHandler($id, $value, $handler);
[128] Fix | Delete
}
[129] Fix | Delete
});
[130] Fix | Delete
} elseif ($value instanceof \YoastSEO_Vendor\GuzzleHttp\Promise\Promise && \YoastSEO_Vendor\GuzzleHttp\Promise\Is::pending($value)) {
[131] Fix | Delete
// We can just merge our handlers onto the next promise.
[132] Fix | Delete
$value->handlers = \array_merge($value->handlers, $handlers);
[133] Fix | Delete
} else {
[134] Fix | Delete
// Resolve the handlers when the forwarded promise is resolved.
[135] Fix | Delete
$value->then(static function ($value) use($handlers) : void {
[136] Fix | Delete
foreach ($handlers as $handler) {
[137] Fix | Delete
self::callHandler(1, $value, $handler);
[138] Fix | Delete
}
[139] Fix | Delete
}, static function ($reason) use($handlers) : void {
[140] Fix | Delete
foreach ($handlers as $handler) {
[141] Fix | Delete
self::callHandler(2, $reason, $handler);
[142] Fix | Delete
}
[143] Fix | Delete
});
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
/**
[147] Fix | Delete
* Call a stack of handlers using a specific callback index and value.
[148] Fix | Delete
*
[149] Fix | Delete
* @param int $index 1 (resolve) or 2 (reject).
[150] Fix | Delete
* @param mixed $value Value to pass to the callback.
[151] Fix | Delete
* @param array $handler Array of handler data (promise and callbacks).
[152] Fix | Delete
*/
[153] Fix | Delete
private static function callHandler(int $index, $value, array $handler) : void
[154] Fix | Delete
{
[155] Fix | Delete
/** @var PromiseInterface $promise */
[156] Fix | Delete
$promise = $handler[0];
[157] Fix | Delete
// The promise may have been cancelled or resolved before placing
[158] Fix | Delete
// this thunk in the queue.
[159] Fix | Delete
if (\YoastSEO_Vendor\GuzzleHttp\Promise\Is::settled($promise)) {
[160] Fix | Delete
return;
[161] Fix | Delete
}
[162] Fix | Delete
try {
[163] Fix | Delete
if (isset($handler[$index])) {
[164] Fix | Delete
/*
[165] Fix | Delete
* If $f throws an exception, then $handler will be in the exception
[166] Fix | Delete
* stack trace. Since $handler contains a reference to the callable
[167] Fix | Delete
* itself we get a circular reference. We clear the $handler
[168] Fix | Delete
* here to avoid that memory leak.
[169] Fix | Delete
*/
[170] Fix | Delete
$f = $handler[$index];
[171] Fix | Delete
unset($handler);
[172] Fix | Delete
$promise->resolve($f($value));
[173] Fix | Delete
} elseif ($index === 1) {
[174] Fix | Delete
// Forward resolution values as-is.
[175] Fix | Delete
$promise->resolve($value);
[176] Fix | Delete
} else {
[177] Fix | Delete
// Forward rejections down the chain.
[178] Fix | Delete
$promise->reject($value);
[179] Fix | Delete
}
[180] Fix | Delete
} catch (\Throwable $reason) {
[181] Fix | Delete
$promise->reject($reason);
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
private function waitIfPending() : void
[185] Fix | Delete
{
[186] Fix | Delete
if ($this->state !== self::PENDING) {
[187] Fix | Delete
return;
[188] Fix | Delete
} elseif ($this->waitFn) {
[189] Fix | Delete
$this->invokeWaitFn();
[190] Fix | Delete
} elseif ($this->waitList) {
[191] Fix | Delete
$this->invokeWaitList();
[192] Fix | Delete
} else {
[193] Fix | Delete
// If there's no wait function, then reject the promise.
[194] Fix | Delete
$this->reject('Cannot wait on a promise that has ' . 'no internal wait function. You must provide a wait ' . 'function when constructing the promise to be able to ' . 'wait on a promise.');
[195] Fix | Delete
}
[196] Fix | Delete
\YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue()->run();
[197] Fix | Delete
/** @psalm-suppress RedundantCondition */
[198] Fix | Delete
if ($this->state === self::PENDING) {
[199] Fix | Delete
$this->reject('Invoking the wait callback did not resolve the promise');
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
private function invokeWaitFn() : void
[203] Fix | Delete
{
[204] Fix | Delete
try {
[205] Fix | Delete
$wfn = $this->waitFn;
[206] Fix | Delete
$this->waitFn = null;
[207] Fix | Delete
$wfn(\true);
[208] Fix | Delete
} catch (\Throwable $reason) {
[209] Fix | Delete
if ($this->state === self::PENDING) {
[210] Fix | Delete
// The promise has not been resolved yet, so reject the promise
[211] Fix | Delete
// with the exception.
[212] Fix | Delete
$this->reject($reason);
[213] Fix | Delete
} else {
[214] Fix | Delete
// The promise was already resolved, so there's a problem in
[215] Fix | Delete
// the application.
[216] Fix | Delete
throw $reason;
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
private function invokeWaitList() : void
[221] Fix | Delete
{
[222] Fix | Delete
$waitList = $this->waitList;
[223] Fix | Delete
$this->waitList = null;
[224] Fix | Delete
foreach ($waitList as $result) {
[225] Fix | Delete
do {
[226] Fix | Delete
$result->waitIfPending();
[227] Fix | Delete
$result = $result->result;
[228] Fix | Delete
} while ($result instanceof \YoastSEO_Vendor\GuzzleHttp\Promise\Promise);
[229] Fix | Delete
if ($result instanceof \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface) {
[230] Fix | Delete
$result->wait(\false);
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function