File tree Expand file tree Collapse file tree 4 files changed +94
-1
lines changed
tests/PHPStan/Rules/Functions Expand file tree Collapse file tree 4 files changed +94
-1
lines changed Original file line number Diff line number Diff line change @@ -181,7 +181,9 @@ public static function selectFromArgs(
181181
182182 $ hasTypes = false ;
183183 $ builder = ConstantArrayTypeBuilder::createEmpty ();
184- foreach ($ optArrayType ->getIterableKeyType ()->getConstantScalarValues () as $ optValue ) {
184+ foreach ($ optArrayType ->getIterableKeyType ()->getConstantScalarTypes () as $ optType ) {
185+ $ optValue = $ optType ->getValue ();
186+
185187 if (!is_int ($ optValue )) {
186188 $ hasTypes = false ;
187189 break ;
@@ -197,6 +199,7 @@ public static function selectFromArgs(
197199 $ builder ->setOffsetValueType (
198200 new ConstantIntegerType ($ optValue ),
199201 $ optValueType ,
202+ !$ optArrayType ->hasOffsetValueType ($ optType )->yes (),
200203 );
201204 }
202205
Original file line number Diff line number Diff line change @@ -2476,4 +2476,16 @@ public function testClone(): void
24762476 ]);
24772477 }
24782478
2479+ #[RequiresPhp('>= 8.1 ' )]
2480+ public function testBug13862 (): void
2481+ {
2482+ $ this ->analyse ([__DIR__ . '/data/bug-13862.php ' ], []);
2483+ }
2484+
2485+ #[RequiresPhp('>= 8.1 ' )]
2486+ public function testBug13862b (): void
2487+ {
2488+ $ this ->analyse ([__DIR__ . '/data/bug-13862b.php ' ], []);
2489+ }
2490+
24792491}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug13862 ;
4+
5+ class foo
6+ {
7+
8+ /**
9+ * @param string $url
10+ * @param string $curl_interface
11+ * @param ?int $port
12+ * @param ?string $post
13+ * @return string
14+ */
15+ public function getUrl (
16+ string $ url ,
17+ string $ curl_interface = "" ,
18+ ?int $ port = null ,
19+ ?string $ post = null
20+ ): string
21+ {
22+
23+ if (empty ($ url ))
24+ return "" ;
25+
26+ $ options = array (
27+ CURLOPT_URL => $ url ,
28+ CURLOPT_CONNECTTIMEOUT => 5 ,
29+ CURLOPT_TIMEOUT => 15 ,
30+ CURLOPT_RETURNTRANSFER => true ,
31+ CURLOPT_PORT => 443 ,
32+ CURLOPT_ENCODING => "gzip, deflate " ,
33+ CURLOPT_HTTPHEADER => array ("Accept-Encoding: gzip, deflate " )
34+ );
35+
36+ if ($ curl_interface != "" )
37+ $ options [CURLOPT_INTERFACE ] = $ curl_interface ;
38+
39+ if ($ port !== null )
40+ $ options [CURLOPT_PORT ] = $ port ;
41+
42+ if ($ post !== null ) {
43+ $ options [CURLOPT_POST ] = true ;
44+ $ options [CURLOPT_POSTFIELDS ] = $ post ;
45+ $ options [CURLOPT_HTTPHEADER ] = array (
46+ "Content-Type: application/json;charset= \"UTF-8 \"" ,
47+ "Accept: application/json " ,
48+ "Accept-Encoding: gzip, deflate " ,
49+ "Content-Length: " . mb_strlen ($ post , "UTF-8 " )
50+ );
51+ }
52+
53+ $ curl = curl_init ();
54+ curl_setopt_array ($ curl , $ options );
55+ $ rc = curl_exec ($ curl );
56+ if (is_bool ($ rc ))
57+ return "" ;
58+ else
59+ return $ rc ;
60+
61+ }
62+
63+ }
64+
65+ $ foo = new foo ();
66+ $ data = $ foo ->getUrl ("https://example.tld " );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug13862b ;
4+
5+ $ options = [];
6+
7+ if (rand ()) {
8+ $ options [CURLOPT_COOKIE ] = 'foo=bar ' ;
9+ }
10+
11+ $ ch = curl_init ();
12+ curl_setopt_array ($ ch , $ options );
You can’t perform that action at this time.
0 commit comments