diff --git a/src/Psalm/Internal/Codebase/ClassLikes.php b/src/Psalm/Internal/Codebase/ClassLikes.php index 372d1da901f..85d281a020b 100644 --- a/src/Psalm/Internal/Codebase/ClassLikes.php +++ b/src/Psalm/Internal/Codebase/ClassLikes.php @@ -377,7 +377,7 @@ public function hasFullyQualifiedClassName( || !$this->classlike_storage_provider->has($fq_class_name_lc) ) { if (( - !isset($this->existing_classes_lc[$fq_class_name_lc]) + !isset($this->existing_classes_lc[$fq_class_name_lc]) || $this->existing_classes_lc[$fq_class_name_lc] ) && !$this->classlike_storage_provider->has($fq_class_name_lc) @@ -417,7 +417,7 @@ public function hasFullyQualifiedInterfaceName( || !$this->classlike_storage_provider->has($fq_class_name_lc) ) { if (( - !isset($this->existing_classes_lc[$fq_class_name_lc]) + !isset($this->existing_classes_lc[$fq_class_name_lc]) || $this->existing_classes_lc[$fq_class_name_lc] ) && !$this->classlike_storage_provider->has($fq_class_name_lc) @@ -484,7 +484,7 @@ public function hasFullyQualifiedEnumName( || !$this->classlike_storage_provider->has($fq_class_name_lc) ) { if (( - !isset($this->existing_classes_lc[$fq_class_name_lc]) + !isset($this->existing_classes_lc[$fq_class_name_lc]) || $this->existing_classes_lc[$fq_class_name_lc] ) && !$this->classlike_storage_provider->has($fq_class_name_lc) @@ -568,7 +568,7 @@ public function classOrInterfaceExists( ?string $calling_method_id = null ): bool { return $this->classExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id) - || $this->interfaceExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id); + || $this->interfaceExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id); } /** @@ -581,8 +581,8 @@ public function classOrInterfaceOrEnumExists( ?string $calling_method_id = null ): bool { return $this->classExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id) - || $this->interfaceExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id) - || $this->enumExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id); + || $this->interfaceExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id) + || $this->enumExists($fq_class_name, $code_location, $calling_fq_class_name, $calling_method_id); } /** @@ -750,7 +750,8 @@ public function classHasCorrectCasing(string $fq_class_name): bool return true; } - if (isset($this->classlike_aliases[strtolower($fq_class_name)])) { + if (isset($this->classlike_aliases[strtolower($fq_class_name)]) && + $this->classlike_aliases[strtolower($fq_class_name)] === $fq_class_name) { return true; } @@ -759,7 +760,8 @@ public function classHasCorrectCasing(string $fq_class_name): bool public function interfaceHasCorrectCasing(string $fq_interface_name): bool { - if (isset($this->classlike_aliases[strtolower($fq_interface_name)])) { + if (isset($this->classlike_aliases[strtolower($fq_interface_name)]) && + $this->classlike_aliases[strtolower($fq_interface_name)] === $fq_interface_name) { return true; } @@ -768,7 +770,8 @@ public function interfaceHasCorrectCasing(string $fq_interface_name): bool public function enumHasCorrectCasing(string $fq_enum_name): bool { - if (isset($this->classlike_aliases[strtolower($fq_enum_name)])) { + if (isset($this->classlike_aliases[strtolower($fq_enum_name)]) && + $this->classlike_aliases[strtolower($fq_enum_name)] === $fq_enum_name) { return true; } @@ -777,7 +780,8 @@ public function enumHasCorrectCasing(string $fq_enum_name): bool public function traitHasCorrectCase(string $fq_trait_name): bool { - if (isset($this->classlike_aliases[strtolower($fq_trait_name)])) { + if (isset($this->classlike_aliases[strtolower($fq_trait_name)]) && + $this->classlike_aliases[strtolower($fq_trait_name)] === $fq_trait_name) { return true; } @@ -907,7 +911,7 @@ public function consolidateAnalyzedData(Methods $methods, ?Progress $progress, b foreach ($stmt->stmts as $namespace_stmt) { if ($namespace_stmt instanceof PhpParser\Node\Stmt\Class_ && strtolower((string) $stmt->name . '\\' . (string) $namespace_stmt->name) - === $fq_class_name_lc + === $fq_class_name_lc ) { self::makeImmutable( $namespace_stmt, @@ -917,7 +921,7 @@ public function consolidateAnalyzedData(Methods $methods, ?Progress $progress, b } } } elseif ($stmt instanceof PhpParser\Node\Stmt\Class_ - && strtolower((string) $stmt->name) === $fq_class_name_lc + && strtolower((string) $stmt->name) === $fq_class_name_lc ) { self::makeImmutable( $stmt, @@ -1226,7 +1230,7 @@ public function handleClassLikeReferenceInMigration( $destination_class = explode('::', $codebase->methods_to_move[$calling_method_id])[0]; $intended_fq_class_name = strtolower($calling_fq_class_name) === strtolower($fq_class_name) - && isset($codebase->classes_to_move[strtolower($calling_fq_class_name)]) + && isset($codebase->classes_to_move[strtolower($calling_fq_class_name)]) ? $destination_class : $fq_class_name; @@ -1308,7 +1312,7 @@ public function handleClassLikeReferenceInMigration( $migrated_source_fqcln, $was_self ) - . ($class_name_node instanceof PhpParser\Node\Scalar\MagicConst\Class_ ? '::class' : '') + . ($class_name_node instanceof PhpParser\Node\Scalar\MagicConst\Class_ ? '::class' : '') ); FileManipulationBuffer::add($source->getFilePath(), $file_manipulations); @@ -1603,7 +1607,7 @@ public function getConstantsForClass(string $class_name, int $visibility): array $storage->constants, function ($constant) { return $constant->type - && $constant->visibility === ClassLikeAnalyzer::VISIBILITY_PUBLIC; + && $constant->visibility === ClassLikeAnalyzer::VISIBILITY_PUBLIC; } ); } @@ -1613,8 +1617,8 @@ function ($constant) { $storage->constants, function ($constant) { return $constant->type - && ($constant->visibility === ClassLikeAnalyzer::VISIBILITY_PUBLIC - || $constant->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED); + && ($constant->visibility === ClassLikeAnalyzer::VISIBILITY_PUBLIC + || $constant->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED); } ); } @@ -1753,7 +1757,7 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth } $has_variable_calls = $codebase->analyzer->hasMixedMemberName($method_name) - || $codebase->analyzer->hasMixedMemberName(strtolower($classlike_storage->name . '::')); + || $codebase->analyzer->hasMixedMemberName(strtolower($classlike_storage->name . '::')); if (isset($classlike_storage->overridden_method_ids[$method_name])) { foreach ($classlike_storage->overridden_method_ids[$method_name] as $parent_method_id) { @@ -1814,8 +1818,8 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth if (!$has_parent_references) { $issue = new PossiblyUnusedMethod( 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') - . ' calls to method ' . $method_id - . ($has_variable_calls ? ' (but did find some potential callers)' : ''), + . ' calls to method ' . $method_id + . ($has_variable_calls ? ' (but did find some potential callers)' : ''), $method_storage->location, $method_id ); @@ -1837,30 +1841,30 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth $issue, $method_storage->suppressed_issues, $method_storage->stmt_location - && !$declaring_classlike_storage->is_trait - && !$has_variable_calls + && !$declaring_classlike_storage->is_trait + && !$has_variable_calls )) { // fall through } } } elseif (!isset($classlike_storage->declaring_method_ids['__call'])) { $has_variable_calls = $codebase->analyzer->hasMixedMemberName( - strtolower($classlike_storage->name . '::') - ) || $codebase->analyzer->hasMixedMemberName($method_name); + strtolower($classlike_storage->name . '::') + ) || $codebase->analyzer->hasMixedMemberName($method_name); if ($method_name === '__construct') { $issue = new UnusedConstructor( 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') - . ' calls to private constructor ' . $method_id - . ($has_variable_calls ? ' (but did find some potential callers)' : ''), + . ' calls to private constructor ' . $method_id + . ($has_variable_calls ? ' (but did find some potential callers)' : ''), $method_location, $method_id ); } else { $issue = new UnusedMethod( 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') - . ' calls to private method ' . $method_id - . ($has_variable_calls ? ' (but did find some potential callers)' : ''), + . ' calls to private method ' . $method_id + . ($has_variable_calls ? ' (but did find some potential callers)' : ''), $method_location, $method_id ); @@ -1883,8 +1887,8 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth $issue, $method_storage->suppressed_issues, $method_storage->stmt_location - && !$declaring_classlike_storage->is_trait - && !$has_variable_calls + && !$declaring_classlike_storage->is_trait + && !$has_variable_calls )) { // fall through } @@ -2051,9 +2055,9 @@ private function findPossibleMethodParamTypes(ClassLikeStorage $classlike_storag ); $has_variable_calls = $codebase->analyzer->hasMixedMemberName( - $method_name - ) - || $codebase->analyzer->hasMixedMemberName( + $method_name + ) + || $codebase->analyzer->hasMixedMemberName( strtolower($classlike_storage->name . '::') ); @@ -2067,7 +2071,7 @@ private function findPossibleMethodParamTypes(ClassLikeStorage $classlike_storag $param_name, $possible_type, $possible_type->from_docblock - && $project_analyzer->only_replace_php_types_with_non_docblock_types + && $project_analyzer->only_replace_php_types_with_non_docblock_types ); } } else { @@ -2101,7 +2105,7 @@ private function checkPropertyReferences(ClassLikeStorage $classlike_storage): v $property_references = $all_method_references[$referenced_property_name]; $property_constructor_referenced = isset($property_references[$constructor_name]) - && !$property_storage->is_static; + && !$property_storage->is_static; } } @@ -2116,7 +2120,7 @@ private function checkPropertyReferences(ClassLikeStorage $classlike_storage): v $has_parent_references = isset($classlike_storage->overridden_property_ids[$property_name]); $has_variable_calls = $codebase->analyzer->hasMixedMemberName('$' . $property_name) - || $codebase->analyzer->hasMixedMemberName(strtolower($classlike_storage->name) . '::$'); + || $codebase->analyzer->hasMixedMemberName(strtolower($classlike_storage->name) . '::$'); foreach ($classlike_storage->parent_classes as $parent_method_fqcln) { if ($codebase->analyzer->hasMixedMemberName( @@ -2142,8 +2146,8 @@ private function checkPropertyReferences(ClassLikeStorage $classlike_storage): v ) { $issue = new PossiblyUnusedProperty( 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') - . ' references to property ' . $property_id - . ($has_variable_calls ? ' (but did find some potential references)' : ''), + . ' references to property ' . $property_id + . ($has_variable_calls ? ' (but did find some potential references)' : ''), $property_storage->location ); @@ -2171,8 +2175,8 @@ private function checkPropertyReferences(ClassLikeStorage $classlike_storage): v $issue = new UnusedProperty( 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') - . ' references to private property ' . $property_id - . ($has_variable_calls ? ' (but did find some potential references)' : ''), + . ' references to private property ' . $property_id + . ($has_variable_calls ? ' (but did find some potential references)' : ''), $property_storage->location ); @@ -2214,7 +2218,7 @@ public function registerMissingClassLike(string $fq_classlike_name_lc): void public function isMissingClassLike(string $fq_classlike_name_lc): bool { return isset($this->existing_classlikes_lc[$fq_classlike_name_lc]) - && $this->existing_classlikes_lc[$fq_classlike_name_lc] === false; + && $this->existing_classlikes_lc[$fq_classlike_name_lc] === false; } /** @@ -2223,7 +2227,7 @@ public function isMissingClassLike(string $fq_classlike_name_lc): bool public function doesClassLikeExist(string $fq_classlike_name_lc): bool { return isset($this->existing_classlikes_lc[$fq_classlike_name_lc]) - && $this->existing_classlikes_lc[$fq_classlike_name_lc]; + && $this->existing_classlikes_lc[$fq_classlike_name_lc]; } public function forgetMissingClassLikes(): void