diff --git a/src/Psalm/FileBasedPluginAdapter.php b/src/Psalm/FileBasedPluginAdapter.php index 14c39a69ccc..6a838bb3cbd 100644 --- a/src/Psalm/FileBasedPluginAdapter.php +++ b/src/Psalm/FileBasedPluginAdapter.php @@ -5,6 +5,7 @@ use Psalm\Internal\Scanner\FileScanner; use SimpleXMLElement; +use function class_exists; use function reset; class FileBasedPluginAdapter implements Plugin\PluginEntryPointInterface @@ -39,6 +40,8 @@ public function __invoke(Plugin\RegistrationInterface $registration, ?SimpleXMLE /** @psalm-suppress UnresolvableInclude */ require_once($this->path); + \assert(class_exists($fq_class_name)); + $registration->registerHooksFromClass($fq_class_name); } diff --git a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php index 825d9a52a4b..f1b66b95e4c 100644 --- a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php @@ -106,8 +106,8 @@ public function __construct(PhpParser\Node\Stmt\ClassLike $class, SourceAnalyzer public function __destruct() { - $this->source = null; - $this->file_analyzer = null; + unset($this->source); + unset($this->file_analyzer); } public function getMethodMutations( diff --git a/src/Psalm/Internal/Analyzer/FileAnalyzer.php b/src/Psalm/Internal/Analyzer/FileAnalyzer.php index fe8c61bebb0..1e6a46c9eb1 100644 --- a/src/Psalm/Internal/Analyzer/FileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FileAnalyzer.php @@ -662,7 +662,6 @@ public function getReturnType() : ?Type\Union public function clearSourceBeforeDestruction() : void { - /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ - $this->source = null; + unset($this->source); } } diff --git a/src/Psalm/Internal/Analyzer/SourceAnalyzer.php b/src/Psalm/Internal/Analyzer/SourceAnalyzer.php index 8e6739564da..ba8d0c31998 100644 --- a/src/Psalm/Internal/Analyzer/SourceAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/SourceAnalyzer.php @@ -18,7 +18,7 @@ abstract class SourceAnalyzer implements StatementsSource public function __destruct() { - $this->source = null; + unset($this->source); } public function getAliases(): Aliases diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index 920fd7e43fc..bbedadc6c62 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -98,10 +98,9 @@ public static function analyze( $case_context->inside_conditional = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $case->cond, $case_context) === false) { - /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ - $case_scope->parent_context = null; - $case_context->case_scope = null; - $case_context->parent_context = null; + unset($case_scope->parent_context); + unset($case_context->case_scope); + unset($case_context->parent_context); return false; } @@ -273,10 +272,9 @@ public static function analyze( $switch_scope->leftover_statements = [$case_if_stmt]; } - /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ - $case_scope->parent_context = null; - $case_context->case_scope = null; - $case_context->parent_context = null; + unset($case_scope->parent_context); + unset($case_context->case_scope); + unset($case_context->parent_context); $statements_analyzer->node_data = $old_node_data; @@ -500,10 +498,9 @@ public static function analyze( $case_exit_type, $switch_scope ) === false) { - /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ - $case_scope->parent_context = null; - $case_context->case_scope = null; - $case_context->parent_context = null; + unset($case_scope->parent_context); + unset($case_context->case_scope); + unset($case_context->parent_context); return false; } @@ -558,10 +555,9 @@ public static function analyze( } } - /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ - $case_scope->parent_context = null; - $case_context->case_scope = null; - $case_context->parent_context = null; + unset($case_scope->parent_context); + unset($case_context->case_scope); + unset($case_context->parent_context); return null; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php index 3d4321764cf..a444bf3c8bb 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -58,7 +58,7 @@ public static function analyze( $existing_thrown_exceptions = $context->possibly_thrown_exceptions; /** - * @var array> + * @var array> $context->possibly_thrown_exceptions */ $context->possibly_thrown_exceptions = []; @@ -270,9 +270,6 @@ public static function analyze( } } - /** - * @var array> - */ $catch_context->possibly_thrown_exceptions = []; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php index 4996ba30157..a84a19e2995 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php @@ -55,7 +55,7 @@ public static function analyze( $left_context->referenced_var_ids = []; $left_context->assigned_var_ids = []; - /** @var list */ + /** @var list $left_context->reconciled_expression_clauses */ $left_context->reconciled_expression_clauses = []; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->left, $left_context) === false) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php index 2327d90e063..01dd1162704 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php @@ -289,8 +289,8 @@ private static function getNumericalType($result): Type\Union } /** - * @param string[] &$invalid_left_messages - * @param string[] &$invalid_right_messages + * @param string[] $invalid_left_messages + * @param string[] $invalid_right_messages */ private static function analyzeOperands( ?StatementsSource $statements_source, diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php index a5c2ba130a0..e5f6d515f91 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ConcatAnalyzer.php @@ -36,7 +36,7 @@ class ConcatAnalyzer { /** - * @param Type\Union|null &$result_type + * @param Type\Union|null $result_type */ public static function analyze( StatementsAnalyzer $statements_analyzer, diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index d7bd9b6ccb6..e4c51bec0a8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -39,10 +39,7 @@ use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent; use Psalm\Storage\FunctionLikeParameter; use Psalm\Type; -use Psalm\Type\Atomic\TArray; -use Psalm\Type\Atomic\TCallable; -use Psalm\Type\Atomic\TClassString; -use Psalm\Type\Atomic\TList; +use Psalm\Type\Atomic; use function array_merge; use function count; @@ -101,11 +98,11 @@ public static function checkArgumentMatches( ) { /** * @psalm-suppress PossiblyUndefinedStringArrayOffset - * @var TList|TArray + * @var Atomic\TList|Atomic\TArray */ $array_type = $param_type->getAtomicTypes()['array']; - if ($array_type instanceof TList) { + if ($array_type instanceof Atomic\TList) { $param_type = $array_type->type_param; } else { $param_type = $array_type->type_params[1]; @@ -313,20 +310,20 @@ private static function checkFunctionLikeTypeMatches( $arg_type_param = null; foreach ($arg_type->getAtomicTypes() as $arg_atomic_type) { - if ($arg_atomic_type instanceof Type\Atomic\TArray - || $arg_atomic_type instanceof Type\Atomic\TList - || $arg_atomic_type instanceof Type\Atomic\TKeyedArray + if ($arg_atomic_type instanceof Atomic\TArray + || $arg_atomic_type instanceof Atomic\TList + || $arg_atomic_type instanceof Atomic\TKeyedArray ) { - if ($arg_atomic_type instanceof Type\Atomic\TKeyedArray) { + if ($arg_atomic_type instanceof Atomic\TKeyedArray) { $arg_type_param = $arg_atomic_type->getGenericValueType(); - } elseif ($arg_atomic_type instanceof Type\Atomic\TList) { + } elseif ($arg_atomic_type instanceof Atomic\TList) { $arg_type_param = $arg_atomic_type->type_param; } else { $arg_type_param = $arg_atomic_type->type_params[1]; } - } elseif ($arg_atomic_type instanceof Type\Atomic\TIterable) { + } elseif ($arg_atomic_type instanceof Atomic\TIterable) { $arg_type_param = $arg_atomic_type->type_params[1]; - } elseif ($arg_atomic_type instanceof Type\Atomic\TNamedObject) { + } elseif ($arg_atomic_type instanceof Atomic\TNamedObject) { ForeachAnalyzer::getKeyValueParamsForTraversableObject( $arg_atomic_type, $codebase, @@ -457,12 +454,12 @@ private static function checkFunctionLikeTypeMatches( if ($arg_type->hasArray()) { /** * @psalm-suppress PossiblyUndefinedStringArrayOffset - * @var Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TKeyedArray|Type\Atomic\TClassStringMap + * @var Atomic\TArray|Atomic\TList|Atomic\TKeyedArray|Atomic\TClassStringMap */ $unpacked_atomic_array = $arg_type->getAtomicTypes()['array']; $arg_key_allowed = true; - if ($unpacked_atomic_array instanceof Type\Atomic\TKeyedArray) { + if ($unpacked_atomic_array instanceof Atomic\TKeyedArray) { if (!$allow_named_args && !$unpacked_atomic_array->getGenericKeyType()->isInt()) { $arg_key_allowed = false; } @@ -493,9 +490,9 @@ private static function checkFunctionLikeTypeMatches( } else { $arg_type = Type::getMixed(); } - } elseif ($unpacked_atomic_array instanceof Type\Atomic\TList) { + } elseif ($unpacked_atomic_array instanceof Atomic\TList) { $arg_type = $unpacked_atomic_array->type_param; - } elseif ($unpacked_atomic_array instanceof Type\Atomic\TClassStringMap) { + } elseif ($unpacked_atomic_array instanceof Atomic\TClassStringMap) { $arg_type = Type::getMixed(); } else { if (!$allow_named_args && !$unpacked_atomic_array->type_params[0]->isInt()) { @@ -653,8 +650,7 @@ private static function checkFunctionLikeTypeMatches( } /** - * @param Type\Atomic\TKeyedArray|Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TClassStringMap - * $unpacked_atomic_array + * @param Atomic\TKeyedArray|Atomic\TArray|Atomic\TList|Atomic\TClassStringMap $unpacked_atomic_array * @return null|false */ public static function verifyType( @@ -835,7 +831,7 @@ public static function verifyType( // we do this replacement early because later we don't have access to the // $statements_analyzer, which is necessary to understand string function names foreach ($input_type->getAtomicTypes() as $key => $atomic_type) { - if (!$atomic_type instanceof Type\Atomic\TLiteralString + if (!$atomic_type instanceof Atomic\TLiteralString || \Psalm\Internal\Codebase\InternalCallMapHandler::inCallMap($atomic_type->value) ) { continue; @@ -902,7 +898,7 @@ public static function verifyType( $potential_method_ids = []; foreach ($input_type->getAtomicTypes() as $input_type_part) { - if ($input_type_part instanceof Type\Atomic\TKeyedArray) { + if ($input_type_part instanceof Atomic\TKeyedArray) { $potential_method_id = CallableTypeComparator::getCallableMethodIdFromTKeyedArray( $input_type_part, $codebase, @@ -913,7 +909,7 @@ public static function verifyType( if ($potential_method_id && $potential_method_id !== 'not-callable') { $potential_method_ids[] = $potential_method_id; } - } elseif ($input_type_part instanceof Type\Atomic\TLiteralString + } elseif ($input_type_part instanceof Atomic\TLiteralString && strpos($input_type_part->value, '::') ) { $parts = explode('::', $input_type_part->value); @@ -1183,7 +1179,7 @@ private static function verifyExplicitParam( $codebase = $statements_analyzer->getCodebase(); foreach ($param_type->getAtomicTypes() as $param_type_part) { - if ($param_type_part instanceof TClassString + if ($param_type_part instanceof Atomic\TClassString && $input_expr instanceof PhpParser\Node\Scalar\String_ && $param_type->isSingle() ) { @@ -1199,11 +1195,11 @@ private static function verifyExplicitParam( ) { return; } - } elseif ($param_type_part instanceof TArray + } elseif ($param_type_part instanceof Atomic\TArray && $input_expr instanceof PhpParser\Node\Expr\Array_ ) { foreach ($param_type_part->type_params[1]->getAtomicTypes() as $param_array_type_part) { - if ($param_array_type_part instanceof TClassString) { + if ($param_array_type_part instanceof Atomic\TClassString) { foreach ($input_expr->items as $item) { if ($item && $item->value instanceof PhpParser\Node\Scalar\String_) { if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName( @@ -1222,7 +1218,7 @@ private static function verifyExplicitParam( } } } - } elseif ($param_type_part instanceof TCallable) { + } elseif ($param_type_part instanceof Atomic\TCallable) { $can_be_callable_like_array = false; if ($param_type->hasArray()) { /** @@ -1231,11 +1227,11 @@ private static function verifyExplicitParam( $param_array_type = $param_type->getAtomicTypes()['array']; $row_type = null; - if ($param_array_type instanceof TList) { + if ($param_array_type instanceof Atomic\TList) { $row_type = $param_array_type->type_param; - } elseif ($param_array_type instanceof TArray) { + } elseif ($param_array_type instanceof Atomic\TArray) { $row_type = $param_array_type->type_params[1]; - } elseif ($param_array_type instanceof Type\Atomic\TKeyedArray) { + } elseif ($param_array_type instanceof Atomic\TKeyedArray) { $row_type = $param_array_type->getGenericArrayType()->type_params[1]; } @@ -1350,8 +1346,7 @@ private static function verifyExplicitParam( } /** - * @param Type\Atomic\TKeyedArray|Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TClassStringMap - * $unpacked_atomic_array + * @param Atomic\TKeyedArray|Atomic\TArray|Atomic\TList|Atomic\TClassStringMap $unpacked_atomic_array */ private static function coerceValueAfterGatekeeperArgument( StatementsAnalyzer $statements_analyzer, @@ -1372,9 +1367,9 @@ private static function coerceValueAfterGatekeeperArgument( $input_type = clone $input_type; foreach ($param_type->getAtomicTypes() as $param_atomic_type) { - if ($param_atomic_type instanceof Type\Atomic\TGenericObject) { + if ($param_atomic_type instanceof Atomic\TGenericObject) { foreach ($input_type->getAtomicTypes() as $input_atomic_type) { - if ($input_atomic_type instanceof Type\Atomic\TGenericObject + if ($input_atomic_type instanceof Atomic\TGenericObject && $input_atomic_type->value === $param_atomic_type->value ) { foreach ($input_atomic_type->type_params as $i => $type_param) { @@ -1445,17 +1440,17 @@ private static function coerceValueAfterGatekeeperArgument( } if ($unpack) { - if ($unpacked_atomic_array instanceof Type\Atomic\TList) { + if ($unpacked_atomic_array instanceof Atomic\TList) { $unpacked_atomic_array = clone $unpacked_atomic_array; $unpacked_atomic_array->type_param = $input_type; $context->vars_in_scope[$var_id] = new Type\Union([$unpacked_atomic_array]); - } elseif ($unpacked_atomic_array instanceof Type\Atomic\TArray) { + } elseif ($unpacked_atomic_array instanceof Atomic\TArray) { $unpacked_atomic_array = clone $unpacked_atomic_array; $unpacked_atomic_array->type_params[1] = $input_type; $context->vars_in_scope[$var_id] = new Type\Union([$unpacked_atomic_array]); - } elseif ($unpacked_atomic_array instanceof Type\Atomic\TKeyedArray + } elseif ($unpacked_atomic_array instanceof Atomic\TKeyedArray && $unpacked_atomic_array->is_list ) { $unpacked_atomic_array = $unpacked_atomic_array->getList(); @@ -1464,7 +1459,7 @@ private static function coerceValueAfterGatekeeperArgument( $context->vars_in_scope[$var_id] = new Type\Union([$unpacked_atomic_array]); } else { $context->vars_in_scope[$var_id] = new Type\Union([ - new TArray([ + new Atomic\TArray([ Type::getInt(), $input_type ]), diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php index ac0f5d241e2..ab58381d33a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php @@ -470,7 +470,7 @@ private static function getIntersectionReturnType( foreach ($intersection_types as $intersection_type) { $intersection_result = clone $result; - /** @var ?Type\Union */ + /** @var ?Type\Union $intersection_result->return_type */ $intersection_result->return_type = null; self::analyze( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index 43a0a13c65d..1b94c2abf64 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -467,8 +467,7 @@ public static function getGenericParamForOffset( } /** - * @param PhpParser\Node\Scalar\String_|PhpParser\Node\Expr\Array_|PhpParser\Node\Expr\BinaryOp\Concat - * $callable_arg + * @param PhpParser\Node\Scalar\String_|PhpParser\Node\Expr\Array_|PhpParser\Node\Expr\BinaryOp\Concat $callable_arg * * @return list * diff --git a/src/Psalm/Internal/Codebase/Scanner.php b/src/Psalm/Internal/Codebase/Scanner.php index 0e41e9414d8..6270c8ea0cf 100644 --- a/src/Psalm/Internal/Codebase/Scanner.php +++ b/src/Psalm/Internal/Codebase/Scanner.php @@ -678,10 +678,6 @@ private function fileExistsForClassLike(ClassLikes $classlikes, string $fq_class return false; } - if (isset($this->existing_classlikes_lc[$fq_class_name_lc])) { - throw new \InvalidArgumentException('Why are you asking about a builtin class?'); - } - $composer_file_path = $this->config->getComposerFilePathForClassLike($fq_class_name); if ($composer_file_path && file_exists($composer_file_path)) { diff --git a/src/Psalm/Internal/Diff/AstDiffer.php b/src/Psalm/Internal/Diff/AstDiffer.php index 89f35a5cd7e..d95ea966b00 100644 --- a/src/Psalm/Internal/Diff/AstDiffer.php +++ b/src/Psalm/Internal/Diff/AstDiffer.php @@ -52,7 +52,6 @@ protected static function calculateTrace( $body_change = false; while ($x < $n && $y < $m && ($is_equal)($a[$x], $b[$y], $a_code, $b_code, $body_change)) { - /** @var bool */ $bc[$x] = $body_change; ++$x; ++$y; diff --git a/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php b/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php index 1e86a9be8eb..91aa4a8709c 100644 --- a/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php @@ -17,5 +17,7 @@ class NodeCounterVisitor extends PhpParser\NodeVisitorAbstract public function enterNode(PhpParser\Node $node) { $this->count++; + + return null; } } diff --git a/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php b/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php index 4a22e8d33c4..499b5f3e199 100644 --- a/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php @@ -69,5 +69,7 @@ public function enterNode(PhpParser\Node $node) $attrs['endFilePos'] + $this->file_offset + ($this->extra_offsets[$attrs['endFilePos']] ?? 0) ); $node->setAttribute('startLine', $attrs['startLine'] + $this->line_offset); + + return null; } } diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 6972bd48aca..8c1a4c320dd 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -636,8 +636,10 @@ public function getAliases(): Aliases return $this->aliases; } - public function afterTraverse(array $nodes): void + public function afterTraverse(array $nodes) { $this->file_storage->type_aliases = $this->type_aliases; + + return null; } } diff --git a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php index e53d99feec7..04d41daa332 100644 --- a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php +++ b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php @@ -9,6 +9,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Name; +use PhpParser\Node\NullableType; use PhpParser\Node\Stmt; use PhpParser\NodeVisitorAbstract; @@ -167,16 +168,14 @@ private function resolveSignature(PhpParser\NodeAbstract $node): void } /** - * @param PhpParser\Node|string|null $node - * - * @return null|PhpParser\Node\Identifier|PhpParser\Node\Name|PhpParser\Node\NullableType - * @psalm-suppress InvalidReturnType - * @psalm-suppress InvalidReturnStatement + * @template T of Node|null + * @param T $node + * @return ($node is NullableType ? NullableType : ($node is Name ? Name : T)) + * @psalm-suppress LessSpecificReturnType */ - private function resolveType($node): ?Node + private function resolveType(?Node $node): ?Node { - if ($node instanceof Node\NullableType) { - /** @psalm-suppress PossiblyInvalidPropertyAssignmentValue */ + if ($node instanceof NullableType) { $node->type = $this->resolveType($node->type); return $node; diff --git a/src/Psalm/Internal/PhpVisitor/TypeMappingVisitor.php b/src/Psalm/Internal/PhpVisitor/TypeMappingVisitor.php index 2a3cbbe5cb2..5266c587f16 100644 --- a/src/Psalm/Internal/PhpVisitor/TypeMappingVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/TypeMappingVisitor.php @@ -18,7 +18,7 @@ public function __construct( $this->real_type_provider = $real_type_provider; } - public function enterNode(Node $node): void + public function enterNode(Node $node) { $origNode = $node; @@ -29,5 +29,7 @@ public function enterNode(Node $node): void /** @psalm-suppress ArgumentTypeCoercion */ $this->real_type_provider->setType($origNode, clone $node_type); } + + return null; } } diff --git a/src/Psalm/Internal/PluginManager/ComposerLock.php b/src/Psalm/Internal/PluginManager/ComposerLock.php index 8fd55bd18c2..b78da0999c9 100644 --- a/src/Psalm/Internal/PluginManager/ComposerLock.php +++ b/src/Psalm/Internal/PluginManager/ComposerLock.php @@ -25,7 +25,7 @@ public function __construct(array $file_names) /** * @param mixed $package * - * @psalm-assert-if-true array $package + * @psalm-assert-if-true array{name: string, extra: array{psalm: array{pluginClass: string}}} $package * * @psalm-pure */ @@ -78,7 +78,6 @@ private function getAllPluginPackages(): array /** @psalm-suppress MixedAssignment */ foreach ($packages as $package) { if ($this->isPlugin($package)) { - /** @var array{name:string,extra:array{psalm:array{pluginClass:string}}} */ $ret[] = $package; } } diff --git a/src/Psalm/Internal/Provider/FakeFileProvider.php b/src/Psalm/Internal/Provider/FakeFileProvider.php index 0a7de8e8303..596fecd9d24 100644 --- a/src/Psalm/Internal/Provider/FakeFileProvider.php +++ b/src/Psalm/Internal/Provider/FakeFileProvider.php @@ -63,7 +63,7 @@ public function getModifiedTime(string $file_path): int public function registerFile(string $file_path, string $file_contents): void { $this->fake_files[$file_path] = $file_contents; - $this->fake_file_times[$file_path] = microtime(true); + $this->fake_file_times[$file_path] = (int)microtime(true); } /** diff --git a/src/Psalm/Internal/Provider/NodeDataProvider.php b/src/Psalm/Internal/Provider/NodeDataProvider.php index 40fe9fc42b0..ce95d7b007d 100644 --- a/src/Psalm/Internal/Provider/NodeDataProvider.php +++ b/src/Psalm/Internal/Provider/NodeDataProvider.php @@ -3,26 +3,24 @@ namespace Psalm\Internal\Provider; use PhpParser; +use PhpParser\Node; use Psalm\Type\Union; use SplObjectStorage; class NodeDataProvider implements \Psalm\NodeTypeProvider { - /** @var SplObjectStorage */ + /** @var SplObjectStorage */ private $node_types; /** - * @var SplObjectStorage< - * PhpParser\Node, - * list>>>|null - * > + * @var SplObjectStorage>>>|null> */ private $node_assertions; - /** @var SplObjectStorage> */ + /** @var SplObjectStorage> */ private $node_if_true_assertions; - /** @var SplObjectStorage> */ + /** @var SplObjectStorage> */ private $node_if_false_assertions; /** @var bool */ @@ -37,7 +35,7 @@ public function __construct() } /** - * @param PhpParser\Node\Expr|PhpParser\Node\Name|PhpParser\Node\Stmt\Return_ $node + * @param Node\Expr|Node\Name|Node\Stmt\Return_ $node */ public function setType(PhpParser\NodeAbstract $node, Union $type) : void { @@ -45,7 +43,7 @@ public function setType(PhpParser\NodeAbstract $node, Union $type) : void } /** - * @param PhpParser\Node\Expr|PhpParser\Node\Name|PhpParser\Node\Stmt\Return_ $node + * @param Node\Expr|Node\Name|Node\Stmt\Return_ $node */ public function getType(PhpParser\NodeAbstract $node) : ?Union { @@ -55,7 +53,7 @@ public function getType(PhpParser\NodeAbstract $node) : ?Union /** * @param list>>>|null $assertions */ - public function setAssertions(PhpParser\Node\Expr $node, ?array $assertions) : void + public function setAssertions(Node\Expr $node, ?array $assertions) : void { if (!$this->cache_assertions) { return; @@ -67,7 +65,7 @@ public function setAssertions(PhpParser\Node\Expr $node, ?array $assertions) : v /** * @return list>>>|null */ - public function getAssertions(PhpParser\Node\Expr $node) : ?array + public function getAssertions(Node\Expr $node) : ?array { if (!$this->cache_assertions) { return null; @@ -77,61 +75,49 @@ public function getAssertions(PhpParser\Node\Expr $node) : ?array } /** - * @param PhpParser\Node\Expr\FuncCall - * |PhpParser\Node\Expr\MethodCall - * |PhpParser\Node\Expr\StaticCall - * |PhpParser\Node\Expr\New_ $node + * @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node * @param array $assertions */ - public function setIfTrueAssertions(PhpParser\Node\Expr $node, array $assertions) : void + public function setIfTrueAssertions(Node\Expr $node, array $assertions) : void { $this->node_if_true_assertions[$node] = $assertions; } /** - * @param PhpParser\Node\Expr\FuncCall - * |PhpParser\Node\Expr\MethodCall - * |PhpParser\Node\Expr\StaticCall - * |PhpParser\Node\Expr\New_ $node + * @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node * @return array|null */ - public function getIfTrueAssertions(PhpParser\Node\Expr $node) : ?array + public function getIfTrueAssertions(Node\Expr $node) : ?array { return $this->node_if_true_assertions[$node] ?? null; } /** - * @param PhpParser\Node\Expr\FuncCall - * |PhpParser\Node\Expr\MethodCall - * |PhpParser\Node\Expr\StaticCall - * |PhpParser\Node\Expr\New_ $node + * @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node * @param array $assertions */ - public function setIfFalseAssertions(PhpParser\Node\Expr $node, array $assertions) : void + public function setIfFalseAssertions(Node\Expr $node, array $assertions) : void { $this->node_if_false_assertions[$node] = $assertions; } /** - * @param PhpParser\Node\Expr\FuncCall - * |PhpParser\Node\Expr\MethodCall - * |PhpParser\Node\Expr\StaticCall - * |PhpParser\Node\Expr\New_ $node + * @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node * @return array|null */ - public function getIfFalseAssertions(PhpParser\Node\Expr $node) : ?array + public function getIfFalseAssertions(Node\Expr $node) : ?array { return $this->node_if_false_assertions[$node] ?? null; } - public function isPureCompatible(PhpParser\Node\Expr $node) : bool + public function isPureCompatible(Node\Expr $node) : bool { $node_type = $this->getType($node); return ($node_type && $node_type->reference_free) || isset($node->pure); } - public function clearNodeOfTypeAndAssertions(PhpParser\Node\Expr $node) : void + public function clearNodeOfTypeAndAssertions(Node\Expr $node) : void { unset($this->node_types[$node], $this->node_assertions[$node]); } diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ExplodeReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ExplodeReturnTypeProvider.php index ae078fcdb34..4e509d97d86 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ExplodeReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ExplodeReturnTypeProvider.php @@ -15,9 +15,6 @@ public static function getFunctionIds() : array return ['explode']; } - /** - * @param list $call_args - */ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event) : Type\Union { $statements_source = $event->getStatementsSource(); diff --git a/src/Psalm/Internal/Scope/CaseScope.php b/src/Psalm/Internal/Scope/CaseScope.php index 220ac60e5e3..fa921007efd 100644 --- a/src/Psalm/Internal/Scope/CaseScope.php +++ b/src/Psalm/Internal/Scope/CaseScope.php @@ -26,6 +26,6 @@ public function __construct(Context $parent_context) public function __destruct() { - $this->parent_context = null; + unset($this->parent_context); } } diff --git a/src/Psalm/Internal/Scope/IfConditionalScope.php b/src/Psalm/Internal/Scope/IfConditionalScope.php index a6791a06566..becf526c905 100644 --- a/src/Psalm/Internal/Scope/IfConditionalScope.php +++ b/src/Psalm/Internal/Scope/IfConditionalScope.php @@ -8,8 +8,10 @@ */ class IfConditionalScope { + /** @var Context */ public $if_context; + /** @var Context */ public $post_if_context; /** diff --git a/src/Psalm/Internal/Scope/LoopScope.php b/src/Psalm/Internal/Scope/LoopScope.php index aa4092df46d..2bbfe903b95 100644 --- a/src/Psalm/Internal/Scope/LoopScope.php +++ b/src/Psalm/Internal/Scope/LoopScope.php @@ -67,7 +67,7 @@ public function __construct(Context $loop_context, Context $parent_context) public function __destruct() { - $this->loop_context = null; - $this->loop_parent_context = null; + unset($this->loop_context); + unset($this->loop_parent_context); } } diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 73bf6160928..320ebc0f379 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1455,7 +1455,7 @@ private static function getArrayTypeFromGenericParams( if (is_int($property_name)) { $objectlike_keys[$property_name] = new TLiteralInt($property_name); - } elseif (isset($type->class_strings[$property_name])) { + } elseif ($type instanceof TKeyedArray && isset($type->class_strings[$property_name])) { $objectlike_keys[$property_name] = new TLiteralClassString($property_name); } else { $objectlike_keys[$property_name] = new TLiteralString($property_name); diff --git a/src/Psalm/Plugin/RegistrationInterface.php b/src/Psalm/Plugin/RegistrationInterface.php index 8bc8a8e0880..c8fedb08f46 100644 --- a/src/Psalm/Plugin/RegistrationInterface.php +++ b/src/Psalm/Plugin/RegistrationInterface.php @@ -9,7 +9,7 @@ interface RegistrationInterface public function addStubFile(string $file_name): void; /** - * @param string class-string $handler + * @param class-string $handler */ public function registerHooksFromClass(string $handler): void; diff --git a/src/Psalm/Plugin/Shepherd.php b/src/Psalm/Plugin/Shepherd.php index a41f001a83e..9e4f5a86149 100644 --- a/src/Psalm/Plugin/Shepherd.php +++ b/src/Psalm/Plugin/Shepherd.php @@ -32,8 +32,6 @@ class Shepherd implements \Psalm\Plugin\EventHandler\AfterAnalysisInterface { /** * Called after analysis is complete - * - * @param array> $issues */ public static function afterAnalysis( AfterAnalysisEvent $event diff --git a/src/Psalm/Type/Atomic/TEnumCase.php b/src/Psalm/Type/Atomic/TEnumCase.php index 2e221f4d05b..9e3815c558c 100644 --- a/src/Psalm/Type/Atomic/TEnumCase.php +++ b/src/Psalm/Type/Atomic/TEnumCase.php @@ -11,9 +11,6 @@ class TEnumCase extends TNamedObject */ public $case_name; - /** - * @param string $value the name of the object - */ public function __construct(string $fq_enum_name, string $case_name) { parent::__construct($fq_enum_name, false);