mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 17:27:28 +01:00
Move mutation checks to more appropriate place
This commit is contained in:
parent
ec9762ce61
commit
556fb12966
@ -607,80 +607,6 @@ class AtomicStaticCallAnalyzer
|
||||
|
||||
$class_storage = $codebase->classlike_storage_provider->get($fq_class_name);
|
||||
|
||||
if ($class_storage->user_defined
|
||||
&& $context->self
|
||||
&& ($context->collect_mutations || $context->collect_initializations)
|
||||
) {
|
||||
$appearing_method_id = $codebase->methods->getAppearingMethodId($method_id);
|
||||
|
||||
if (!$appearing_method_id) {
|
||||
if (IssueBuffer::accepts(
|
||||
new UndefinedMethod(
|
||||
'Method ' . $method_id . ' does not exist',
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt),
|
||||
(string) $method_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
//
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$appearing_method_class_name = $appearing_method_id->fq_class_name;
|
||||
|
||||
if ($codebase->classExtends($context->self, $appearing_method_class_name)) {
|
||||
$old_context_include_location = $context->include_location;
|
||||
$old_self = $context->self;
|
||||
$context->include_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
|
||||
$context->self = $appearing_method_class_name;
|
||||
|
||||
$file_analyzer = $statements_analyzer->getFileAnalyzer();
|
||||
|
||||
if ($context->collect_mutations) {
|
||||
$file_analyzer->getMethodMutations($method_id, $context);
|
||||
} else {
|
||||
// collecting initializations
|
||||
$local_vars_in_scope = [];
|
||||
$local_vars_possibly_in_scope = [];
|
||||
|
||||
foreach ($context->vars_in_scope as $var => $_) {
|
||||
if (strpos($var, '$this->') !== 0 && $var !== '$this') {
|
||||
$local_vars_in_scope[$var] = $context->vars_in_scope[$var];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($context->vars_possibly_in_scope as $var => $_) {
|
||||
if (strpos($var, '$this->') !== 0 && $var !== '$this') {
|
||||
$local_vars_possibly_in_scope[$var] = $context->vars_possibly_in_scope[$var];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($context->initialized_methods[(string) $method_id])) {
|
||||
if ($context->initialized_methods === null) {
|
||||
$context->initialized_methods = [];
|
||||
}
|
||||
|
||||
$context->initialized_methods[(string) $method_id] = true;
|
||||
|
||||
$file_analyzer->getMethodMutations($method_id, $context);
|
||||
|
||||
foreach ($local_vars_in_scope as $var => $type) {
|
||||
$context->vars_in_scope[$var] = $type;
|
||||
}
|
||||
|
||||
foreach ($local_vars_possibly_in_scope as $var => $type) {
|
||||
$context->vars_possibly_in_scope[$var] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$context->include_location = $old_context_include_location;
|
||||
$context->self = $old_self;
|
||||
}
|
||||
}
|
||||
|
||||
if ($class_storage->deprecated && $fq_class_name !== $context->self) {
|
||||
if (IssueBuffer::accepts(
|
||||
new DeprecatedClass(
|
||||
|
@ -59,6 +59,69 @@ class ExistingAtomicStaticCallAnalyzer
|
||||
// fall through
|
||||
}
|
||||
|
||||
if ($class_storage->user_defined
|
||||
&& $context->self
|
||||
&& ($context->collect_mutations || $context->collect_initializations)
|
||||
) {
|
||||
$appearing_method_id = $codebase->methods->getAppearingMethodId($method_id);
|
||||
|
||||
if (!$appearing_method_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$appearing_method_class_name = $appearing_method_id->fq_class_name;
|
||||
|
||||
if ($codebase->classExtends($context->self, $appearing_method_class_name)) {
|
||||
$old_context_include_location = $context->include_location;
|
||||
$old_self = $context->self;
|
||||
$context->include_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
|
||||
$context->self = $appearing_method_class_name;
|
||||
|
||||
$file_analyzer = $statements_analyzer->getFileAnalyzer();
|
||||
|
||||
if ($context->collect_mutations) {
|
||||
$file_analyzer->getMethodMutations($method_id, $context);
|
||||
} else {
|
||||
// collecting initializations
|
||||
$local_vars_in_scope = [];
|
||||
$local_vars_possibly_in_scope = [];
|
||||
|
||||
foreach ($context->vars_in_scope as $var => $_) {
|
||||
if (strpos($var, '$this->') !== 0 && $var !== '$this') {
|
||||
$local_vars_in_scope[$var] = $context->vars_in_scope[$var];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($context->vars_possibly_in_scope as $var => $_) {
|
||||
if (strpos($var, '$this->') !== 0 && $var !== '$this') {
|
||||
$local_vars_possibly_in_scope[$var] = $context->vars_possibly_in_scope[$var];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($context->initialized_methods[(string) $method_id])) {
|
||||
if ($context->initialized_methods === null) {
|
||||
$context->initialized_methods = [];
|
||||
}
|
||||
|
||||
$context->initialized_methods[(string) $method_id] = true;
|
||||
|
||||
$file_analyzer->getMethodMutations($method_id, $context);
|
||||
|
||||
foreach ($local_vars_in_scope as $var => $type) {
|
||||
$context->vars_in_scope[$var] = $type;
|
||||
}
|
||||
|
||||
foreach ($local_vars_possibly_in_scope as $var => $type) {
|
||||
$context->vars_possibly_in_scope[$var] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$context->include_location = $old_context_include_location;
|
||||
$context->self = $old_self;
|
||||
}
|
||||
}
|
||||
|
||||
$found_generic_params = ClassTemplateParamCollector::collect(
|
||||
$codebase,
|
||||
$class_storage,
|
||||
|
Loading…
Reference in New Issue
Block a user