mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #1090 - re-fix support for magic get properties
This commit is contained in:
parent
3ccd9f4c01
commit
116cbfd349
@ -256,12 +256,7 @@ class PropertyAssignmentAnalyzer
|
||||
$property_id = $lhs_type_part->value . '::$' . $prop_name;
|
||||
$property_ids[] = $property_id;
|
||||
|
||||
$statements_analyzer_source = $statements_analyzer->getSource();
|
||||
|
||||
if ($codebase->methodExists($lhs_type_part->value . '::__set')
|
||||
&& (!$statements_analyzer_source instanceof FunctionLikeAnalyzer
|
||||
|| $statements_analyzer_source->getMethodId() !== $lhs_type_part->value . '::__set')
|
||||
&& (!$context->self || !$codebase->classExtends($context->self, $lhs_type_part->value))
|
||||
&& (!$codebase->properties->propertyExists($property_id)
|
||||
|| ($lhs_var_id !== '$this'
|
||||
&& $lhs_type_part->value !== $context->self
|
||||
|
@ -291,12 +291,7 @@ class PropertyFetchAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
$statements_analyzer_source = $statements_analyzer->getSource();
|
||||
|
||||
if ($codebase->methodExists($lhs_type_part->value . '::__get')
|
||||
&& (!$statements_analyzer_source instanceof FunctionLikeAnalyzer
|
||||
|| $statements_analyzer_source->getMethodId() !== $lhs_type_part->value . '::__get')
|
||||
&& (!$context->self || !$codebase->classExtends($context->self, $lhs_type_part->value))
|
||||
&& (!$codebase->properties->propertyExists($property_id)
|
||||
|| ($stmt_var_id !== '$this'
|
||||
&& $lhs_type_part->value !== $context->self
|
||||
|
@ -323,6 +323,22 @@ class MagicPropertyTest extends TestCase
|
||||
'assertions' => [],
|
||||
'error_level' => ['MixedArgument'],
|
||||
],
|
||||
'accessInMagicGet' => [
|
||||
'<?php
|
||||
class X {
|
||||
public function __get(string $name) : string {
|
||||
switch ($name) {
|
||||
case "a":
|
||||
return $this->other;
|
||||
case "other":
|
||||
return "foo";
|
||||
}
|
||||
return "default";
|
||||
}
|
||||
}',
|
||||
'assertions' => [],
|
||||
'error_level' => ['MixedReturnStatement', 'MixedInferredReturnType'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -612,22 +628,6 @@ class MagicPropertyTest extends TestCase
|
||||
'error_message' => 'MixedTypeCoercion',
|
||||
'error_levels' => ['MixedAssignment'],
|
||||
],
|
||||
'misnamedPropertyByVariable' => [
|
||||
'<?php
|
||||
class B {
|
||||
/** @var string|null */
|
||||
public $foo;
|
||||
|
||||
public function __get(string $var_name) : ?string {
|
||||
if ($var_name === "bar") {
|
||||
return $this->$var_name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}',
|
||||
'error_message' => 'UndefinedThisPropertyFetch',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1809,6 +1809,22 @@ class PropertyTypeTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'UndefinedMethod',
|
||||
],
|
||||
'misnamedPropertyByVariable' => [
|
||||
'<?php
|
||||
class B {
|
||||
/** @var string|null */
|
||||
public $foo;
|
||||
|
||||
public function bar(string $var_name) : ?string {
|
||||
if ($var_name === "bar") {
|
||||
return $this->$var_name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}',
|
||||
'error_message' => 'UndefinedThisPropertyFetch',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user