-
Notifications
You must be signed in to change notification settings - Fork 61
fix: correct phpstan config error #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,14 +149,17 @@ public function send(RequestInterface $request): ResponseInterface | |
| // If retry was still set to false, it means no event handler | ||
| // dealt with the problem. In this case we just re-throw the | ||
| // exception. | ||
| // @phpstan-ignore booleanNot.alwaysTrue | ||
| if (!$retry) { | ||
| throw $e; | ||
| } | ||
| } | ||
|
|
||
| // @phpstan-ignore if.alwaysFalse | ||
| if ($retry) { | ||
| ++$retryCount; | ||
| } | ||
| // @phpstan-ignore booleanOr.leftAlwaysFalse | ||
| } while ($retry || $doRedirect); | ||
|
|
||
| $this->emit('afterRequest', [$request, $response]); | ||
|
|
@@ -228,6 +231,7 @@ public function poll(): bool | |
| $e = new ClientException($curlResult['curl_errmsg'], $curlResult['curl_errno']); | ||
| $this->emit('exception', [$request, $e, &$retry, $retryCount]); | ||
|
|
||
| // @phpstan-ignore if.alwaysFalse | ||
| if ($retry) { | ||
| ++$retryCount; | ||
| $this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount); | ||
|
|
@@ -236,13 +240,15 @@ public function poll(): bool | |
|
|
||
| $curlResult['request'] = $request; | ||
|
|
||
| // @phpstan-ignore function.alreadyNarrowedType | ||
| if (is_callable($errorCallback)) { | ||
| $errorCallback($curlResult); | ||
| } | ||
| } elseif (self::STATUS_HTTPERROR === $curlResult['status']) { | ||
| $this->emit('error', [$request, $curlResult['response'], &$retry, $retryCount]); | ||
| $this->emit('error:'.$curlResult['http_code'], [$request, $curlResult['response'], &$retry, $retryCount]); | ||
|
|
||
| // @phpstan-ignore if.alwaysFalse | ||
| if ($retry) { | ||
| ++$retryCount; | ||
| $this->sendAsyncInternal($request, $successCallback, $errorCallback, $retryCount); | ||
|
|
@@ -251,12 +257,14 @@ public function poll(): bool | |
|
|
||
| $curlResult['request'] = $request; | ||
|
|
||
| // @phpstan-ignore function.alreadyNarrowedType | ||
| if (is_callable($errorCallback)) { | ||
| $errorCallback($curlResult); | ||
| } | ||
| } else { | ||
| $this->emit('afterRequest', [$request, $curlResult['response']]); | ||
|
|
||
| // @phpstan-ignore function.alreadyNarrowedType | ||
| if (is_callable($successCallback)) { | ||
| $successCallback($curlResult['response']); | ||
| } | ||
|
|
@@ -299,7 +307,7 @@ public function setThrowExceptions(bool $throwExceptions): void | |
| * | ||
| * These settings will be included in every HTTP request. | ||
| */ | ||
| public function addCurlSetting(int $name, $value): void | ||
| public function addCurlSetting(int $name, mixed $value): void | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| $this->curlSettings[$name] = $value; | ||
| } | ||
|
|
@@ -311,10 +319,10 @@ protected function doRequest(RequestInterface $request): ResponseInterface | |
| { | ||
| $settings = $this->createCurlSettingsArray($request); | ||
|
|
||
| if (null === $this->curlHandle) { | ||
| $this->curlHandle = curl_init(); | ||
| } else { | ||
| if (isset($this->curlHandle)) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| curl_reset($this->curlHandle); | ||
| } else { | ||
| $this->curlHandle = curl_init(); | ||
| } | ||
|
|
||
| curl_setopt_array($this->curlHandle, $settings); | ||
|
|
@@ -332,17 +340,15 @@ protected function doRequest(RequestInterface $request): ResponseInterface | |
| * | ||
| * By keeping this resource around for the lifetime of this object, things | ||
| * like persistent connections are possible. | ||
| * | ||
| * @var resource|null | ||
| */ | ||
| private $curlHandle; | ||
| private \CurlHandle $curlHandle; | ||
|
|
||
| /** | ||
| * Handler for curl_multi requests. | ||
| * | ||
| * The first time sendAsync is used, this will be created. | ||
| * | ||
| * @var resource|null | ||
| * @var \CurlMultiHandle|null | ||
| */ | ||
| private $curlMultiHandle; | ||
|
|
||
|
|
@@ -382,6 +388,7 @@ protected function createCurlSettingsArray(RequestInterface $request): array | |
| // reason. | ||
| $settings[CURLOPT_PUT] = true; | ||
| $settings[CURLOPT_INFILE] = $body; | ||
| // @phpstan-ignore function.alreadyNarrowedType | ||
| if (false !== $bodyStat && array_key_exists('size', $bodyStat)) { | ||
| $settings[CURLOPT_INFILESIZE] = $bodyStat['size']; | ||
| } | ||
|
|
@@ -426,7 +433,7 @@ protected function createCurlSettingsArray(RequestInterface $request): array | |
| public const STATUS_HTTPERROR = 2; | ||
|
|
||
| /** | ||
| * @param resource $curlHandle | ||
| * @param \CurlHandle $curlHandle | ||
| * | ||
| * @return mixed[] | ||
| */ | ||
|
|
@@ -466,7 +473,7 @@ private function parseResponse(string $response, $curlHandle): array | |
| * status is STATUS_SUCCESS, or STATUS_HTTPERROR | ||
| * | ||
| * @param array<int, string> $headerLines | ||
| * @param resource $curlHandle | ||
| * @param \CurlHandle $curlHandle | ||
| * | ||
| * @return array<string, mixed> | ||
| */ | ||
|
|
@@ -523,7 +530,7 @@ protected function parseCurlResponse(array $headerLines, string $body, $curlHand | |
| * | ||
| * @deprecated Use parseCurlResponse instead | ||
| * | ||
| * @param resource $curlHandle | ||
| * @param \CurlHandle $curlHandle | ||
| * | ||
| * @return array<string, mixed> | ||
| */ | ||
|
|
@@ -548,6 +555,7 @@ protected function parseCurlResult(string $response, $curlHandle): array | |
| // This will cause substr($response, $curlInfo['header_size']) return FALSE instead of NULL | ||
| // An exception will be thrown when calling getBodyAsString then | ||
| $responseBody = substr($response, $curlInfo['header_size']); | ||
| // @phpstan-ignore identical.alwaysFalse | ||
| if (false === $responseBody) { | ||
| $responseBody = ''; | ||
| } | ||
|
|
@@ -603,7 +611,7 @@ protected function sendAsyncInternal(RequestInterface $request, callable $succes | |
| * | ||
| * This method exists so that it can easily be overridden and mocked. | ||
| * | ||
| * @param resource $curlHandle | ||
| * @param \CurlHandle $curlHandle | ||
| */ | ||
| protected function curlExec($curlHandle): string | ||
| { | ||
|
|
@@ -622,7 +630,7 @@ protected function curlExec($curlHandle): string | |
| * | ||
| * This method exists so that it can easily be overridden and mocked. | ||
| * | ||
| * @param resource $curlHandle | ||
| * @param \CurlHandle $curlHandle | ||
| * | ||
| * @return array<int, mixed> | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For most of these, phpstan is noticing "defensive" code.
In this case
$retryhas been passed toemitin a way that is potentially writeable.So maybe it could have value either
trueorfalsehere?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Pass-by-ref is hard to properly analyze. Needs a new phpstan issue with a small reproducer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phpstan/phpstan#15116