mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
parent
4010129e96
commit
4b1c3db760
@ -758,7 +758,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer
|
||||
}
|
||||
|
||||
if (!$args && $lhs_var_id) {
|
||||
if ($config->memoize_method_calls || $can_memoize) {
|
||||
if (($config->memoize_method_calls || $can_memoize) && !$plain_getter_property) {
|
||||
$method_var_id = $lhs_var_id . '->' . $method_name_lc . '()';
|
||||
|
||||
if (isset($context->vars_in_scope[$method_var_id])) {
|
||||
|
@ -727,6 +727,54 @@ class ConfigTest extends \Psalm\Tests\TestCase
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testUnchainedMethodCallMemoize()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__, 2),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm memoizeMethodCallResults="true">
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
class SomeClass {
|
||||
private ?int $int;
|
||||
|
||||
public function __construct() {
|
||||
$this->int = 1;
|
||||
}
|
||||
|
||||
public function getInt(): ?int {
|
||||
return $this->int;
|
||||
}
|
||||
}
|
||||
|
||||
function printInt(int $int): void {
|
||||
echo $int;
|
||||
}
|
||||
|
||||
$obj = new SomeClass();
|
||||
|
||||
if ($obj->getInt()) {
|
||||
printInt($obj->getInt());
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user