1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Memoize private inferred mutation-free methods (#4832)

This commit is contained in:
2e3s 2020-12-12 10:26:14 -05:00 committed by Daniil Gentili
parent 519edd9251
commit fadb3a76e7
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 24 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace Psalm\Internal\Analyzer\Statements\Expression\Call\Method;
use PhpParser;
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Codebase;
use Psalm\CodeLocation;
@ -79,7 +80,8 @@ class MethodCallPurityAnalyzer
) {
if ($method_storage->mutation_free
&& (!$method_storage->mutation_free_inferred
|| $method_storage->final)
|| $method_storage->final
|| $method_storage->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE)
&& ($method_storage->immutable || $config->remember_property_assignments_after_call)
) {
if ($context->inside_conditional

View File

@ -857,6 +857,27 @@ class MethodCallTest extends TestCase
printInt($obj->getInt());
}',
],
'privateInferredMutationFreeMethodCallMemoize' => [
'<?php
class PropertyClass {
public function test() : void {
echo "test";
}
}
class SomeClass {
private ?PropertyClass $property = null;
private function getProperty(): ?PropertyClass {
return $this->property;
}
public function test(int $int): void {
if ($this->getProperty() !== null) {
$this->getProperty()->test();
}
}
}',
],
'inferredFinalMethod' => [
'<?php
class PropertyClass {