Skip to content
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

Update Curl is_resource() to work with PHP 8 CurlHandle and CurlMultiHandle objects #2715

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 91 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,101 @@ parameters:
count: 1
path: src/Client.php

-
message: "#^Property GuzzleHttp\\\\Handler\\\\CurlFactory\\:\\:\\$handles has unknown class CurlHandle as its type\\.$#"
count: 1
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_setopt_array expects resource, CurlHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_close expects resource, CurlHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_setopt expects resource, CurlHandle\\|resource given\\.$#"
count: 4
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_reset expects resource, CurlHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_getinfo expects resource, CurlHandle\\|resource given\\.$#"
count: 4
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_error expects resource, CurlHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$str1 of function strcasecmp expects string, int\\|string given\\.$#"
count: 1
path: src/Handler/CurlFactory.php

-
message: "#^Parameter \\#1 \\$ch of function curl_exec expects resource, CurlHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlHandler.php

-
message: "#^Parameter \\#1 \\$ch of function curl_errno expects resource, CurlHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlHandler.php

-
message: "#^Property GuzzleHttp\\\\Handler\\\\CurlMultiHandler\\:\\:\\$active has unknown class CurlMultiHandle as its type\\.$#"
count: 1
path: src/Handler/CurlMultiHandler.php

-
message: "#^Return typehint of method GuzzleHttp\\\\Handler\\\\CurlMultiHandler\\:\\:__get\\(\\) has invalid type CurlMultiHandle\\.$#"
count: 1
path: src/Handler/CurlMultiHandler.php

-
message: "#^Parameter \\#1 \\$mh of function curl_multi_close expects resource, CurlMultiHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlMultiHandler.php

-
message: "#^Parameter \\#1 \\$mh of function curl_multi_add_handle expects resource, CurlMultiHandle\\|resource given\\.$#"
count: 2
path: src/Handler/CurlMultiHandler.php

-
message: "#^Parameter \\#1 \\$mh of function curl_multi_select expects resource, CurlMultiHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlMultiHandler.php

-
message: "#^Parameter \\#1 \\$mh of function curl_multi_exec expects resource, CurlMultiHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlMultiHandler.php

-
message: "#^Parameter \\#1 \\$mh of function curl_multi_remove_handle expects resource, CurlMultiHandle\\|resource given\\.$#"
count: 2
path: src/Handler/CurlMultiHandler.php

-
message: "#^Parameter \\#1 \\$mh of function curl_multi_info_read expects resource, CurlMultiHandle\\|resource given\\.$#"
count: 1
path: src/Handler/CurlMultiHandler.php

-
message: "#^Property GuzzleHttp\\\\Handler\\\\EasyHandle\\:\\:\\$handle has unknown class CurlHandle as its type\\.$#"
count: 1
path: src/Handler/EasyHandle.php

-
message: "#^Argument of an invalid type \\(array\\|null\\) supplied for foreach, only iterables are supported\\.$#"
count: 1
Expand All @@ -19,3 +109,4 @@ parameters:
message: "#^Result of && is always false\\.$#"
count: 2
path: src/Middleware.php

59 changes: 42 additions & 17 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.11.5@3c60609c218d4d4b3b257728b8089094e5c6c6c2">
<files psalm-version="3.16@d03e5ef057d6adc656c0ff7e166c50b73b4f48f3">
<file src="src/Client.php">
<NullArgument occurrences="1">
<code>null</code>
</NullArgument>
<PossiblyUndefinedVariable occurrences="1">
<code>$options</code>
</PossiblyUndefinedVariable>
Expand All @@ -22,28 +19,59 @@
</ImplicitToStringCast>
</file>
<file src="src/Handler/CurlFactory.php">
<ImplicitToStringCast occurrences="1">
<code>$easy-&gt;request-&gt;getUri()</code>
</ImplicitToStringCast>
<PossiblyInvalidArgument occurrences="12">
<code>$easy-&gt;handle</code>
<code>$easy-&gt;handle</code>
<code>$easy-&gt;handle</code>
<code>$easy-&gt;handle</code>
<code>$easy-&gt;handle</code>
<code>$easy-&gt;handle</code>
<code>$resource</code>
<code>$resource</code>
<code>$resource</code>
<code>$resource</code>
<code>$resource</code>
<code>$resource</code>
</PossiblyInvalidArgument>
<TypeDoesNotContainType occurrences="1">
<code>$timeoutRequiresNoSignal &amp;&amp; \strtoupper(\substr(\PHP_OS, 0, 3)) !== 'WIN'</code>
</TypeDoesNotContainType>
<UndefinedDocblockClass occurrences="2">
<code>private $handles = [];</code>
<code>resource[]|\CurlHandle[]</code>
</UndefinedDocblockClass>
</file>
<file src="src/Handler/CurlHandler.php">
<PossiblyInvalidArgument occurrences="2">
<code>$easy-&gt;handle</code>
<code>$easy-&gt;handle</code>
</PossiblyInvalidArgument>
</file>
<file src="src/Handler/CurlMultiHandler.php">
<InvalidArgument occurrences="1">
<code>$this-&gt;active</code>
</InvalidArgument>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;active</code>
</InvalidPropertyAssignmentValue>
<PossiblyInvalidArgument occurrences="7">
<code>$this-&gt;_mh</code>
<code>$this-&gt;_mh</code>
<code>$this-&gt;_mh</code>
<code>$this-&gt;_mh</code>
<code>$this-&gt;_mh</code>
<code>$this-&gt;_mh</code>
<code>$this-&gt;_mh</code>
</PossiblyInvalidArgument>
<UndefinedDocblockClass occurrences="2">
<code>resource|\CurlMultiHandle</code>
<code>resource|\CurlMultiHandle|null</code>
</UndefinedDocblockClass>
<UndefinedThisPropertyAssignment occurrences="1">
<code>$this-&gt;_mh</code>
</UndefinedThisPropertyAssignment>
</file>
<file src="src/Handler/MockHandler.php">
<InvalidScalarArgument occurrences="1">
<code>$options['delay'] * 1000</code>
</InvalidScalarArgument>
<file src="src/Handler/EasyHandle.php">
<UndefinedDocblockClass occurrences="1">
<code>resource|\CurlHandle</code>
</UndefinedDocblockClass>
</file>
<file src="src/Handler/StreamHandler.php">
<ImplicitToStringCast occurrences="1">
Expand Down Expand Up @@ -80,8 +108,5 @@
<ForbiddenCode occurrences="1">
<code>\var_dump($input)</code>
</ForbiddenCode>
<PossiblyNullArgument occurrences="1">
<code>$info</code>
</PossiblyNullArgument>
</file>
</files>
2 changes: 1 addition & 1 deletion src/Handler/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CurlFactory implements CurlFactoryInterface
public const LOW_CURL_VERSION_NUMBER = '7.21.2';

/**
* @var resource[]
* @var resource[]|\CurlHandle[]
*/
private $handles = [];

Expand Down
6 changes: 3 additions & 3 deletions src/Handler/CurlMultiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* associative array of curl option constants mapping to values in the
* **curl** key of the provided request options.
*
* @property resource $_mh Internal use only. Lazy loaded multi-handle.
* @property resource|\CurlMultiHandle $_mh Internal use only. Lazy loaded multi-handle.
*
* @final
*/
Expand All @@ -32,7 +32,7 @@ class CurlMultiHandler
private $selectTimeout;

/**
* @var resource|null the currently executing resource in `curl_multi_exec`.
* @var resource|\CurlMultiHandle|null the currently executing resource in `curl_multi_exec`.
*/
private $active;

Expand Down Expand Up @@ -83,7 +83,7 @@ public function __construct(array $options = [])
/**
* @param string $name
*
* @return resource
* @return resource|\CurlMultiHandle
*
* @throws \BadMethodCallException when another field as `_mh` will be gotten
* @throws \RuntimeException when curl can not initialize a multi handle
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/EasyHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class EasyHandle
{
/**
* @var resource cURL resource
* @var resource|\CurlHandle cURL resource
*/
public $handle;

Expand Down
6 changes: 5 additions & 1 deletion tests/Handler/CurlFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public function testCreatesCurlHandle()
$f = new Handler\CurlFactory(3);
$result = $f->create($request, ['sink' => $stream]);
self::assertInstanceOf(EasyHandle::class, $result);
self::assertIsResource($result->handle);
if (\PHP_VERSION_ID >= 80000) {
self::assertInstanceOf(\CurlHandle::class, $result->handle);
} else {
self::assertIsResource($result->handle);
}
self::assertIsArray($result->headers);
self::assertSame($stream, $result->sink);
\curl_close($result->handle);
Expand Down