diff --git a/examples/plugins/FunctionCasingChecker.php b/examples/plugins/FunctionCasingChecker.php index 67dd3bbf2..96775977b 100644 --- a/examples/plugins/FunctionCasingChecker.php +++ b/examples/plugins/FunctionCasingChecker.php @@ -94,6 +94,10 @@ class FunctionCasingChecker implements AfterFunctionCallAnalysisInterface, After $function_id ); + if (!$function_storage->cased_name) { + return; + } + $function_name_parts = explode('\\', $function_storage->cased_name); if (end($function_name_parts) !== end($expr->name->parts)) { diff --git a/psalm.xml.dist b/psalm.xml.dist index fafa1343a..85b1e751f 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -49,18 +49,13 @@ - - + + - - - - - + - - + diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index cdd0fdbe8..fa1aa8dc6 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -751,6 +751,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer } if (!($storage instanceof MethodStorage) + || !$storage->cased_name || $storage->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE ) { if ($this->function instanceof Closure) { @@ -804,6 +805,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer if ($storage instanceof MethodStorage && $class_storage + && $storage->cased_name && $storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PRIVATE ) { $method_id_lc = strtolower($this->getMethodId()); @@ -816,7 +818,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer $method_id_lc ); - /** @var ClassMethod $this->function */ $method_name_lc = strtolower($storage->cased_name); if (!isset($class_storage->overridden_method_ids[$method_name_lc])) { diff --git a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php index 7da8c2e5f..be505a18e 100644 --- a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php @@ -520,7 +520,7 @@ class MethodAnalyzer extends FunctionLikeAnalyzer $prevent_method_signature_mismatch = true ) { $implementer_method_id = $implementer_classlike_storage->name . '::' - . strtolower($guide_method_storage->cased_name); + . strtolower($guide_method_storage->cased_name ?: ''); $implementer_declaring_method_id = $codebase->methods->getDeclaringMethodId($implementer_method_id); @@ -694,7 +694,7 @@ class MethodAnalyzer extends FunctionLikeAnalyzer $template_types = []; foreach ($map as $key => $type) { - if (is_string($key)) { + if (is_string($key) && $implementer_method_storage->defining_fqcln) { $template_types[$key][$implementer_method_storage->defining_fqcln] = [ $type, ]; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php index e63f640ed..a2767c85e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php @@ -259,9 +259,7 @@ class SwitchAnalyzer } $case_context->parent_context = $context; - $case_scope = $case_context->case_scope = new CaseScope(); - - $case_scope->parent_context = $case_context; + $case_scope = $case_context->case_scope = new CaseScope($case_context); $case_equality_expr = null; diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index b51891dc5..0ecaab0f2 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -527,7 +527,7 @@ class Methods list($fq_class_name, $method_name) = explode('::', $method_id); - return $this->classlike_storage_provider->get($fq_class_name)->methods[$method_name]->variadic; + return $this->classlike_storage_provider->get($fq_class_name)->methods[$method_name ?: '']->variadic; } /** diff --git a/src/Psalm/Internal/Codebase/Scanner.php b/src/Psalm/Internal/Codebase/Scanner.php index 7643b6d30..1397b6d35 100644 --- a/src/Psalm/Internal/Codebase/Scanner.php +++ b/src/Psalm/Internal/Codebase/Scanner.php @@ -638,8 +638,13 @@ class Scanner if ($this->codebase->register_autoload_files) { foreach ($file_storage->functions as $function_storage) { - if (!$this->codebase->functions->hasStubbedFunction($function_storage->cased_name)) { - $this->codebase->functions->addGlobalFunction($function_storage->cased_name, $function_storage); + if ($function_storage->cased_name + && !$this->codebase->functions->hasStubbedFunction($function_storage->cased_name) + ) { + $this->codebase->functions->addGlobalFunction( + $function_storage->cased_name, + $function_storage + ); } } diff --git a/src/Psalm/Internal/Scope/CaseScope.php b/src/Psalm/Internal/Scope/CaseScope.php index 151cd4ba7..d3359e160 100644 --- a/src/Psalm/Internal/Scope/CaseScope.php +++ b/src/Psalm/Internal/Scope/CaseScope.php @@ -25,6 +25,11 @@ class CaseScope */ public $break_vars; + public function __construct(Context $parent_context) + { + $this->parent_context = $parent_context; + } + public function __destruct() { /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ diff --git a/src/Psalm/Storage/FunctionLikeStorage.php b/src/Psalm/Storage/FunctionLikeStorage.php index 17d1c2bd9..209b0e406 100644 --- a/src/Psalm/Storage/FunctionLikeStorage.php +++ b/src/Psalm/Storage/FunctionLikeStorage.php @@ -57,7 +57,7 @@ class FunctionLikeStorage public $signature_return_type_location; /** - * @var string + * @var ?string */ public $cased_name; @@ -67,12 +67,12 @@ class FunctionLikeStorage public $suppressed_issues = []; /** - * @var bool + * @var ?bool */ public $deprecated; /** - * @var bool + * @var ?bool */ public $internal; @@ -84,7 +84,7 @@ class FunctionLikeStorage /** * @var bool */ - public $variadic; + public $variadic = false; /** * @var bool @@ -92,7 +92,7 @@ class FunctionLikeStorage public $returns_by_ref = false; /** - * @var int + * @var ?int */ public $required_param_count; diff --git a/src/Psalm/Storage/MethodStorage.php b/src/Psalm/Storage/MethodStorage.php index aa5e94121..e6575e50b 100644 --- a/src/Psalm/Storage/MethodStorage.php +++ b/src/Psalm/Storage/MethodStorage.php @@ -6,22 +6,22 @@ class MethodStorage extends FunctionLikeStorage /** * @var bool */ - public $is_static; + public $is_static = false; /** * @var int */ - public $visibility; + public $visibility = 0; /** * @var bool */ - public $final; + public $final = false; /** * @var bool */ - public $abstract; + public $abstract = false; /** * @var bool @@ -44,7 +44,7 @@ class MethodStorage extends FunctionLikeStorage public $inherited_return_type = false; /** - * @var string + * @var ?string */ public $defining_fqcln; diff --git a/src/Psalm/Storage/PropertyStorage.php b/src/Psalm/Storage/PropertyStorage.php index aa75126ee..fc080af39 100644 --- a/src/Psalm/Storage/PropertyStorage.php +++ b/src/Psalm/Storage/PropertyStorage.php @@ -10,14 +10,14 @@ class PropertyStorage use CustomMetadataTrait; /** - * @var bool + * @var ?bool */ public $is_static; /** * @var int */ - public $visibility; + public $visibility = 0; /** * @var CodeLocation|null