Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More precise file() flags args in bleedingEdge #2476

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/functionMap_bleedingEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>|false', 'filename'=>'string', 'flags='=>'0|FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES', 'context='=>'resource'],
Copy link
Contributor

@iluuu1994 iluuu1994 Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be missing the FILE_NO_DEFAULT_CONTEXT flag (which is apparently undocumented).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks will have a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added via #2482

I missed it, because its missing from https://www.php.net/manual/en/function.file.php - therefore just also sumbitted a php.net docs PR

],
'old' => [

Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 0|1|2|4, 8 given.',
16,
],
]);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Functions/data/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace fileFlags;

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);
}

public function error():void {
$f = file(__FILE__, FILE_APPEND);
}
}