Skip to content

Commit b61d340

Browse files
committed
Narrow CURLOPT_SHARE accepting type
1 parent 3db4f49 commit b61d340

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
@@ -58,6 +58,7 @@
5858
use function sprintf;
5959
use const ARRAY_FILTER_USE_BOTH;
6060
use const ARRAY_FILTER_USE_KEY;
61+
use const CURLOPT_SHARE;
6162
use const CURLOPT_SSL_VERIFYHOST;
6263

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

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

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)