Skip to content

Commit 3592cf0

Browse files
authoredSep 6, 2024
Don't prevent checking for curl_init() false returns
1 parent d9b4267 commit 3592cf0

10 files changed

+20
-275
lines changed
 

‎conf/config.neon

-5
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,6 @@ services:
13601360
tags:
13611361
- phpstan.broker.dynamicFunctionReturnTypeExtension
13621362

1363-
-
1364-
class: PHPStan\Type\Php\CurlInitReturnTypeExtension
1365-
tags:
1366-
- phpstan.broker.dynamicFunctionReturnTypeExtension
1367-
13681363
-
13691364
class: PHPStan\Type\Php\DateFunctionReturnTypeHelper
13701365

‎resources/functionMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@
14941494
'curl_exec' => ['bool|string', 'ch'=>'resource'],
14951495
'curl_file_create' => ['CURLFile', 'filename'=>'string', 'mimetype='=>'string', 'postfilename='=>'string'],
14961496
'curl_getinfo' => ['mixed', 'ch'=>'resource', 'option='=>'int'],
1497-
'curl_init' => ['resource|false', 'url='=>'string'],
1497+
'curl_init' => ['__benevolent<resource|false>', 'url='=>'string'],
14981498
'curl_multi_add_handle' => ['int', 'mh'=>'resource', 'ch'=>'resource'],
14991499
'curl_multi_close' => ['void', 'mh'=>'resource'],
15001500
'curl_multi_errno' => ['int', 'mh'=>'resource'],

‎resources/functionMap_php80delta.php

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'ceil' => ['float', 'number'=>'float'],
3232
'com_load_typelib' => ['bool', 'typelib_name'=>'string', 'case_insensitive='=>'true'],
3333
'count_chars' => ['array<int,int>|string', 'input'=>'string', 'mode='=>'int'],
34+
'curl_init' => ['__benevolent<CurlHandle|false>', 'url='=>'string'],
3435
'date_add' => ['DateTime', 'object'=>'DateTime', 'interval'=>'DateInterval'],
3536
'date_date_set' => ['DateTime', 'object'=>'DateTime', 'year'=>'int', 'month'=>'int', 'day'=>'int'],
3637
'date_diff' => ['DateInterval', 'obj1'=>'DateTimeInterface', 'obj2'=>'DateTimeInterface', 'absolute='=>'bool'],
@@ -169,6 +170,7 @@
169170
'convert_cyr_string' => ['string', 'str'=>'string', 'from'=>'string', 'to'=>'string'],
170171
'com_load_typelib' => ['bool', 'typelib_name'=>'string', 'case_insensitive='=>'bool'],
171172
'count_chars' => ['array<int,int>|false|string', 'input'=>'string', 'mode='=>'int'],
173+
'curl_init' => ['__benevolent<resource|false>', 'url='=>'string'],
172174
'date_add' => ['DateTime|false', 'object'=>'DateTime', 'interval'=>'DateInterval'],
173175
'date_date_set' => ['DateTime|false', 'object'=>'DateTime', 'year'=>'int', 'month'=>'int', 'day'=>'int'],
174176
'date_diff' => ['DateInterval|false', 'obj1'=>'DateTimeInterface', 'obj2'=>'DateTimeInterface', 'absolute='=>'bool'],

‎src/Type/Php/CurlInitReturnTypeExtension.php

-102
This file was deleted.

‎tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,12 @@ public function testBug11511(): void
14371437
$this->assertSame('Access to an undefined property object::$bar.', $errors[0]->getMessage());
14381438
}
14391439

1440+
public function testBug11640(): void
1441+
{
1442+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-11640.php');
1443+
$this->assertNoErrors($errors);
1444+
}
1445+
14401446
/**
14411447
* @param string[]|null $allAnalysedFiles
14421448
* @return Error[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11640;
4+
5+
$ch = curl_init('https://example.com');
6+
7+
if (!$ch) {
8+
9+
}

‎tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Reflection\PassedByReference;
1313
use PHPStan\Testing\PHPStanTestCase;
1414
use PHPStan\Type\ArrayType;
15+
use PHPStan\Type\BenevolentUnionType;
1516
use PHPStan\Type\BooleanType;
1617
use PHPStan\Type\CallableType;
1718
use PHPStan\Type\ClassStringType;
@@ -59,7 +60,7 @@ public function dataFunctions(): array
5960
'variadic' => false,
6061
],
6162
],
62-
new UnionType([
63+
new BenevolentUnionType([
6364
new ObjectType('CurlHandle'),
6465
new ConstantBooleanType(false),
6566
]),

‎tests/PHPStan/Type/Php/CurlInitReturnTypeExtensionTest.php

-32
This file was deleted.

‎tests/PHPStan/Type/Php/data/curl-init-php-7.php

-65
This file was deleted.

‎tests/PHPStan/Type/Php/data/curl-init-php-8.php

-69
This file was deleted.

0 commit comments

Comments
 (0)