Skip to content

Commit ef50cec

Browse files
Invalidate filesize
1 parent 0132833 commit ef50cec

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,8 +2398,10 @@ static function (): void {
23982398
&& $functionReflection->getName() === 'file_put_contents'
23992399
&& count($expr->getArgs()) > 0
24002400
) {
2401-
$scope = $scope->invalidateExpression(new FuncCall(new Name('file_get_contents'), [$expr->getArgs()[0]]))
2402-
->invalidateExpression(new FuncCall(new Name\FullyQualified('file_get_contents'), [$expr->getArgs()[0]]));
2401+
foreach (['file_get_contents', 'filesize'] as $functionToInvalidate) {
2402+
$scope = $scope->invalidateExpression(new FuncCall(new Name($functionToInvalidate), [$expr->getArgs()[0]]))
2403+
->invalidateExpression(new FuncCall(new Name\FullyQualified($functionToInvalidate), [$expr->getArgs()[0]]));
2404+
}
24032405
}
24042406

24052407
if (

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,9 @@ public function testBug6467(): void
231231
$this->analyse([__DIR__ . '/data/bug-6467.php'], []);
232232
}
233233

234+
public function testBug11484(): void
235+
{
236+
$this->analyse([__DIR__ . '/data/bug-11484.php'], []);
237+
}
238+
234239
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11484;
4+
5+
class HelloWorld
6+
{
7+
public function sayHello(): void
8+
{
9+
if (filesize("file.txt") > 100) {
10+
file_put_contents("file.txt", str_repeat('aaaaaaa', rand(1,100)));
11+
if (filesize("file.txt") > 50) {
12+
13+
}
14+
}
15+
16+
}
17+
}

0 commit comments

Comments
 (0)