Skip to content

Commit 7cea174

Browse files
committed
Narrow CURLOPT_SHARE accepting type
1 parent 0d793ec commit 7cea174

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
use function sprintf;
6060
use const ARRAY_FILTER_USE_BOTH;
6161
use const ARRAY_FILTER_USE_KEY;
62+
use const CURLOPT_SHARE;
6263
use const CURLOPT_SSL_VERIFYHOST;
6364

6465
/**
@@ -1213,6 +1214,14 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
12131214
}
12141215
}
12151216

1217+
if ($curlOpt === CURLOPT_SHARE) {
1218+
return new UnionType([
1219+
new ResourceType(), // PHP 7.x
1220+
new ObjectType('CurlShareHandle'), // since PHP 8.0
1221+
new ObjectType('CurlSharePersistentHandle'), // since PHP 8.5
1222+
]);
1223+
}
1224+
12161225
// unknown constant
12171226
return null;
12181227
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,10 @@ public function testCurlSetOpt(): void
13981398
'Parameter #3 $value of function curl_setopt expects bool|int, int|string given.',
13991399
96,
14001400
],
1401+
[
1402+
'Parameter #3 $value of function curl_setopt expects CurlShareHandle|CurlSharePersistentHandle|resource, string given.',
1403+
101,
1404+
],
14011405
]);
14021406
}
14031407

tests/PHPStan/Rules/Functions/data/curl_setopt.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,17 @@ public function unionType() {
9595

9696
curl_setopt($curl, $var, $value);
9797
}
98+
99+
public function curlShare() {
100+
$curl = curl_init();
101+
curl_setopt($curl, CURLOPT_SHARE, 'this is wrong');
102+
103+
$share = curl_share_init();
104+
curl_setopt($curl, CURLOPT_SHARE, $share);
105+
106+
if (function_exists('curl_share_init_persistent')) {
107+
$share = curl_share_init_persistent();
108+
curl_setopt($curl, CURLOPT_SHARE, $share);
109+
}
110+
}
98111
}

0 commit comments

Comments
 (0)