From 2eb0e6fc73f14cf43fe58da4d5a8f5c363ea64d6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 21 Jun 2023 21:10:27 +0200 Subject: [PATCH 1/3] More precise file() flags args in bleedingEdge --- resources/functionMap_bleedingEdge.php | 1 + .../CallToFunctionParametersRuleTest.php | 10 ++++++++++ tests/PHPStan/Rules/Functions/data/file.php | 15 +++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/PHPStan/Rules/Functions/data/file.php diff --git a/resources/functionMap_bleedingEdge.php b/resources/functionMap_bleedingEdge.php index ed9768c9f6..8560362f11 100644 --- a/resources/functionMap_bleedingEdge.php +++ b/resources/functionMap_bleedingEdge.php @@ -107,6 +107,7 @@ 'ImagickKernel::scale' => ['void', 'scale'=>'float', 'normalizeFlag'=>'Imagick::NORMALIZE_KERNEL_*'], 'max' => ['', '...arg1'=>'non-empty-array'], 'min' => ['', '...arg1'=>'non-empty-array'], + 'file' => ['list|false', 'filename'=>'string', 'flags='=>'FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES', 'context='=>'resource'], ], 'old' => [ diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 67a9726043..37b7d92807 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -1368,4 +1368,14 @@ public function testBenevolentSuperglobalKeys(): void $this->analyse([__DIR__ . '/data/benevolent-superglobal-keys.php'], []); } + public function testFileParams(): void + { + $this->analyse([__DIR__ . '/data/file.php'], [ + [ + 'Parameter #2 $flags of function file expects 1|2|4, 8 given.', + 13, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/file.php b/tests/PHPStan/Rules/Functions/data/file.php new file mode 100644 index 0000000000..0ec740ab97 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/file.php @@ -0,0 +1,15 @@ + Date: Wed, 21 Jun 2023 21:15:39 +0200 Subject: [PATCH 2/3] fix namespace --- tests/PHPStan/Rules/Functions/data/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPStan/Rules/Functions/data/file.php b/tests/PHPStan/Rules/Functions/data/file.php index 0ec740ab97..0eb1fb9a19 100644 --- a/tests/PHPStan/Rules/Functions/data/file.php +++ b/tests/PHPStan/Rules/Functions/data/file.php @@ -1,6 +1,6 @@ Date: Wed, 21 Jun 2023 21:19:40 +0200 Subject: [PATCH 3/3] another test --- resources/functionMap_bleedingEdge.php | 2 +- .../Rules/Functions/CallToFunctionParametersRuleTest.php | 4 ++-- tests/PHPStan/Rules/Functions/data/file.php | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/functionMap_bleedingEdge.php b/resources/functionMap_bleedingEdge.php index 8560362f11..f154d74d5f 100644 --- a/resources/functionMap_bleedingEdge.php +++ b/resources/functionMap_bleedingEdge.php @@ -107,7 +107,7 @@ 'ImagickKernel::scale' => ['void', 'scale'=>'float', 'normalizeFlag'=>'Imagick::NORMALIZE_KERNEL_*'], 'max' => ['', '...arg1'=>'non-empty-array'], 'min' => ['', '...arg1'=>'non-empty-array'], - 'file' => ['list|false', 'filename'=>'string', 'flags='=>'FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES', 'context='=>'resource'], + 'file' => ['list|false', 'filename'=>'string', 'flags='=>'0|FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES', 'context='=>'resource'], ], 'old' => [ diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 37b7d92807..b5ecc1ae9e 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -1372,8 +1372,8 @@ public function testFileParams(): void { $this->analyse([__DIR__ . '/data/file.php'], [ [ - 'Parameter #2 $flags of function file expects 1|2|4, 8 given.', - 13, + 'Parameter #2 $flags of function file expects 0|1|2|4, 8 given.', + 16, ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/file.php b/tests/PHPStan/Rules/Functions/data/file.php index 0eb1fb9a19..77c32f64af 100644 --- a/tests/PHPStan/Rules/Functions/data/file.php +++ b/tests/PHPStan/Rules/Functions/data/file.php @@ -4,6 +4,9 @@ class Foo { public function ok():void { + $lines = file('http://www.example.com/'); + $lines1 = file('http://www.example.com/', 0); + $f1 = file(__FILE__, FILE_USE_INCLUDE_PATH); $f2 = file(__FILE__, FILE_IGNORE_NEW_LINES); $f3 = file(__FILE__, FILE_SKIP_EMPTY_LINES);