Skip to content

Commit

Permalink
Improve pure method detection and mark Redis::get explicitly impure
Browse files Browse the repository at this point in the history
Refs #10215
  • Loading branch information
curry684 committed Nov 29, 2023
1 parent 093bbb2 commit f9e5efa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/functionMetadata_original.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
'DateTimeImmutable::getTimestamp' => ['hasSideEffects' => false],
'DateTimeImmutable::getTimezone' => ['hasSideEffects' => false],

'Redis::get' => ['hasSideEffects' => true],

'XmlReader::next' => ['hasSideEffects' => true],
'XmlReader::read' => ['hasSideEffects' => true],
];
5 changes: 5 additions & 0 deletions src/Reflection/Php/PhpMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
use PHPStan\Type\VoidType;
use ReflectionException;
use function array_map;
use function count;
use function explode;
use function filemtime;
use function in_array;
use function is_bool;
use function preg_match;
use function sprintf;
use function strtolower;
use function time;
Expand Down Expand Up @@ -429,6 +431,9 @@ public function hasSideEffects(): TrinaryLogic
if ($this->isPure !== null) {
return TrinaryLogic::createFromBoolean(!$this->isPure);
}
if (count($this->getParameters()) === 0 && preg_match('#^(get|is|has|can)[A-Z0-9_]#', $this->getName())) {

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Only booleans are allowed in &&, int|false given on the right side.

Check failure on line 434 in src/Reflection/Php/PhpMethodReflection.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Only booleans are allowed in &&, int|false given on the right side.
return TrinaryLogic::createNo();
}

return TrinaryLogic::createMaybe();
}
Expand Down

0 comments on commit f9e5efa

Please sign in to comment.