diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 617d8f394bb..b09a704d2c2 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -543,9 +543,7 @@ public function decrementReferenceCount(string $ref_id): void /** * @param Clause[] $clauses * @param array $changed_var_ids - * * @return array{list, list} - * * @psalm-pure */ public static function removeReconciledClauses(array $clauses, array $changed_var_ids): array @@ -574,7 +572,6 @@ public static function removeReconciledClauses(array $clauses, array $changed_va /** * @param Clause[] $clauses - * * @return list */ public static function filterClauses( diff --git a/src/Psalm/Internal/Algebra.php b/src/Psalm/Internal/Algebra.php index 2032d912c90..d93b5820519 100644 --- a/src/Psalm/Internal/Algebra.php +++ b/src/Psalm/Internal/Algebra.php @@ -76,9 +76,7 @@ public static function negateTypes(array $all_types): array * (!$a) && (!$b) && ($a || $b || $c) => $c * * @param list $clauses - * * @return list - * * @psalm-pure */ public static function simplifyCNF(array $clauses): array @@ -209,7 +207,7 @@ public static function simplifyCNF(array $clauses): array } else { $updated_clause = $clause_b->addPossibilities( $clause_var, - $clause_var_possibilities + $clause_var_possibilities, ); $cloned_clauses[$updated_clause->hash] = $updated_clause; @@ -257,7 +255,7 @@ public static function simplifyCNF(array $clauses): array for ($k = $i + 1; $k < $clause_count; $k++) { $clause_b = $clauses[$k]; $common_keys = array_keys( - array_intersect_key($clause_a->possibilities, $clause_b->possibilities) + array_intersect_key($clause_a->possibilities, $clause_b->possibilities), ); if ($common_keys) { $common_negated_keys = []; @@ -265,7 +263,7 @@ public static function simplifyCNF(array $clauses): array if (count($clause_a->possibilities[$common_key]) === 1 && count($clause_b->possibilities[$common_key]) === 1 && reset($clause_a->possibilities[$common_key])->isNegationOf( - reset($clause_b->possibilities[$common_key]) + reset($clause_b->possibilities[$common_key]), ) ) { $common_negated_keys[] = $common_key; @@ -313,7 +311,7 @@ public static function simplifyCNF(array $clauses): array false, true, true, - [] + [], )); unset($simplified_clauses[$conflict_clause->hash]); @@ -335,7 +333,6 @@ public static function simplifyCNF(array $clauses): array * @param list $clauses * @param array $cond_referenced_var_ids * @param array>> $active_truths - * * @return array>> */ public static function getTruthsFromFormula( @@ -472,9 +469,7 @@ public static function getTruthsFromFormula( /** * @param non-empty-list $clauses - * * @return list - * * @psalm-pure */ public static function groupImpossibilities(array $clauses): array @@ -495,7 +490,7 @@ public static function groupImpossibilities(array $clauses): array $seed_clause = new Clause( [$var => [(string)$impossible_type => $impossible_type]], $clause->creating_conditional_id, - $clause->creating_object_id + $clause->creating_object_id, ); $seed_clauses[] = $seed_clause; @@ -568,7 +563,7 @@ public static function groupImpossibilities(array $clauses): array false, true, true, - [] + [], ); $new_clauses[] = $new_clause; @@ -591,9 +586,7 @@ public static function groupImpossibilities(array $clauses): array /** * @param list $left_clauses * @param list $right_clauses - * * @return list - * * @psalm-pure */ public static function combineOredClauses( @@ -686,7 +679,7 @@ public static function combineOredClauses( || $left_clause->generated || count($left_clauses) > 1 || count($right_clauses) > 1, - [] + [], ); } } @@ -714,14 +707,13 @@ public static function combineOredClauses( * (!$a || !$c || !$f) * * @param list $clauses - * * @return non-empty-list */ public static function negateFormula(array $clauses): array { $clauses = array_filter( $clauses, - static fn(Clause $clause): bool => $clause->reconcilable + static fn(Clause $clause): bool => $clause->reconcilable, ); if (!$clauses) { diff --git a/src/Psalm/Internal/Algebra/FormulaGenerator.php b/src/Psalm/Internal/Algebra/FormulaGenerator.php index 3387098123e..e6e42b7b4f9 100644 --- a/src/Psalm/Internal/Algebra/FormulaGenerator.php +++ b/src/Psalm/Internal/Algebra/FormulaGenerator.php @@ -209,8 +209,8 @@ public static function getFormula( $this_class_name, $source, $codebase, - !$inside_negation - ) + !$inside_negation, + ), ); } @@ -235,8 +235,8 @@ public static function getFormula( $source, $codebase, !$inside_negation, - $cache - ) + $cache, + ), ); } @@ -255,8 +255,8 @@ public static function getFormula( $source, $codebase, !$inside_negation, - $cache - ) + $cache, + ), ); } @@ -318,8 +318,8 @@ public static function getFormula( $source, $codebase, !$inside_negation, - $cache - ) + $cache, + ), ); } @@ -338,8 +338,8 @@ public static function getFormula( $source, $codebase, !$inside_negation, - $cache - ) + $cache, + ), ); } @@ -455,8 +455,8 @@ public static function getFormula( new Clause( [$conditional_ref => ['truthy' => new Truthy()]], $conditional_object_id, - $creating_object_id - ) + $creating_object_id, + ), ]; } } diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 91db65f845d..da8043935be 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -159,7 +159,7 @@ public function analyze( NodeDataProvider $type_provider, ?Context $global_context = null, bool $add_mutations = false, - array &$byref_vars = [] + array &$byref_vars = [], ): ?bool { $storage = $this->storage; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php index dc13f8c7972..3fc0b4f3563 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php @@ -87,8 +87,8 @@ static function (Clause $c) use ($mixed_var_ids): bool { } return true; - } - ) + }, + ), ); if (!$while_clauses) { @@ -117,8 +117,8 @@ static function (Clause $c) use ($mixed_var_ids): bool { $negated_while_types = Algebra::getTruthsFromFormula( Algebra::simplifyCNF( - [...$context->clauses, ...$negated_while_clauses] - ) + [...$context->clauses, ...$negated_while_clauses], + ), ); if ($negated_while_types) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php index c839ce2cc43..00a588f5dfd 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php @@ -81,7 +81,7 @@ public static function analyze( static fn(Clause $c): bool => count($c->possibilities) > 1 || $c->wedge || !isset($changed_var_ids[array_keys($c->possibilities)[0]]) - ) + ), ); } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php index 5bb2e11d8bc..568a19e1a88 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php @@ -53,7 +53,7 @@ public static function analyze( } $else_context->clauses = Algebra::simplifyCNF( - [...$else_context->clauses, ...$if_scope->negated_clauses] + [...$else_context->clauses, ...$if_scope->negated_clauses], ); $else_types = Algebra::getTruthsFromFormula($else_context->clauses); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php index 5289d69974e..f4aa30a1982 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php @@ -147,7 +147,7 @@ public static function analyze( array_filter( $elseif_context_clauses, static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses, true) - ) + ), ); } @@ -158,7 +158,7 @@ public static function analyze( try { if (array_filter( $entry_clauses, - static fn(Clause $clause): bool => (bool) $clause->possibilities + static fn(Clause $clause): bool => (bool) $clause->possibilities, )) { $omit_keys = array_reduce( $entry_clauses, @@ -186,7 +186,7 @@ public static function analyze( $active_elseif_types, ); $negated_elseif_types = Algebra::getTruthsFromFormula( - Algebra::negateFormula($elseif_clauses) + Algebra::negateFormula($elseif_clauses), ); } catch (ComplicatedExpressionException) { $reconcilable_elseif_types = []; @@ -405,7 +405,7 @@ public static function analyze( try { $if_scope->negated_clauses = Algebra::simplifyCNF( - [...$if_scope->negated_clauses, ...Algebra::negateFormula($elseif_clauses)] + [...$if_scope->negated_clauses, ...Algebra::negateFormula($elseif_clauses)], ); } catch (ComplicatedExpressionException) { $if_scope->negated_clauses = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php index ec432661dca..f33c93d86f0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php @@ -76,7 +76,7 @@ public static function analyze( if (array_filter( $outer_context->clauses, - static fn(Clause $clause): bool => (bool) $clause->possibilities + static fn(Clause $clause): bool => (bool) $clause->possibilities, )) { $omit_keys = array_reduce( $outer_context->clauses, diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php index 8bf7f9fc859..60e3acaa964 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php @@ -564,7 +564,6 @@ private static function updateLoopScopeContexts( /** * @param list $pre_condition_clauses - * * @return list */ private static function applyPreConditionToLoopContext( @@ -596,7 +595,7 @@ private static function applyPreConditionToLoopContext( $always_assigned_before_loop_body_vars = Context::getNewOrUpdatedVarIds($outer_context, $loop_context); $loop_context->clauses = Algebra::simplifyCNF( - [...$outer_context->clauses, ...$pre_condition_clauses] + [...$outer_context->clauses, ...$pre_condition_clauses], ); $active_while_types = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php index 149d2a73461..ee9d7cb1822 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php @@ -144,7 +144,7 @@ public static function analyze( if (!$has_default && $switch_scope->negated_clauses && $switch_var_id) { $entry_clauses = Algebra::simplifyCNF( - [...$original_context->clauses, ...$switch_scope->negated_clauses] + [...$original_context->clauses, ...$switch_scope->negated_clauses], ); $reconcilable_if_types = Algebra::getTruthsFromFormula($entry_clauses); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index 6353659c1d1..a5a9f51e542 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -358,7 +358,7 @@ public static function analyze( if ($switch_scope->negated_clauses && count($switch_scope->negated_clauses) < 50) { $entry_clauses = Algebra::simplifyCNF( - [...$original_context->clauses, ...$switch_scope->negated_clauses] + [...$original_context->clauses, ...$switch_scope->negated_clauses], ); } else { $entry_clauses = $original_context->clauses; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php index 04e61d7ad6a..e7134d07487 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php @@ -182,7 +182,7 @@ public static function analyze( array_filter( $negated_left_clauses, static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses) - ) + ), ); if (count($negated_left_clauses) === 1 @@ -194,7 +194,7 @@ public static function analyze( } $clauses_for_right_analysis = Algebra::simplifyCNF( - [...$context->clauses, ...$negated_left_clauses] + [...$context->clauses, ...$negated_left_clauses], ); $active_negated_type_assertions = []; @@ -297,7 +297,7 @@ public static function analyze( )[0]; $combined_right_clauses = Algebra::simplifyCNF( - [...$clauses_for_right_analysis, ...$right_clauses] + [...$clauses_for_right_analysis, ...$right_clauses], ); $active_right_type_assertions = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index 6bf6d89bbd6..0e081a2c67c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -848,8 +848,8 @@ public static function applyAssertionsToContext( $arg_value, $context->self, $statements_analyzer, - $codebase - ) + $codebase, + ), ); } elseif ($single_rule instanceof IsType && $single_rule->type instanceof TTrue @@ -870,11 +870,11 @@ public static function applyAssertionsToContext( } $simplified_clauses = Algebra::simplifyCNF( - [...$context->clauses, ...$assert_clauses] + [...$context->clauses, ...$assert_clauses], ); $assert_type_assertions = Algebra::getTruthsFromFormula( - $simplified_clauses + $simplified_clauses, ); $type_assertions = [...$type_assertions, ...$assert_type_assertions]; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php index 9cdc9c6d477..33b733bc8b6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php @@ -1747,15 +1747,11 @@ private static function handleArrayAccessOnKeyedArray( } } - /** - * @param Type\Union|Type\MutableUnion $array_type - * @param Type\Union|Type\MutableUnion $offset_type - */ public static function validateArrayOffset( StatementsAnalyzer $statements_analyzer, Expr $stmt, - $array_type, - $offset_type + Type\Union|Type\MutableUnion $array_type, + Type\Union|Type\MutableUnion $offset_type, ): void { $all_arrays_shaped = true; $exact_keys = null; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php index 65dcfc3af3e..38ab1befc28 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php @@ -262,7 +262,7 @@ public static function analyze( ); $reconcilable_types = Algebra::getTruthsFromFormula( - Algebra::negateFormula($clauses) + Algebra::negateFormula($clauses), ); // if the if has an || in the conditional, we cannot easily reason about it diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php index 143acd29917..9c574e7a0f8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php @@ -114,7 +114,7 @@ static function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause { return $c; }, - $if_clauses + $if_clauses, ); $entry_clauses = $context->clauses; @@ -141,7 +141,7 @@ static function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause { array_filter( $ternary_context_clauses, static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses) - ) + ), ); if (count($if_context->clauses) === 1 @@ -173,8 +173,8 @@ static function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause { $if_scope->negated_types = Algebra::getTruthsFromFormula( Algebra::simplifyCNF( - [...$context->clauses, ...$if_scope->negated_clauses] - ) + [...$context->clauses, ...$if_scope->negated_clauses], + ), ); $active_if_types = []; @@ -217,7 +217,7 @@ static function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause { } $t_else_context->clauses = Algebra::simplifyCNF( - [...$t_else_context->clauses, ...$if_scope->negated_clauses] + [...$t_else_context->clauses, ...$if_scope->negated_clauses], ); $changed_var_ids = []; diff --git a/src/Psalm/Internal/Clause.php b/src/Psalm/Internal/Clause.php index cf2e9a681f8..31c8e2804b0 100644 --- a/src/Psalm/Internal/Clause.php +++ b/src/Psalm/Internal/Clause.php @@ -65,10 +65,9 @@ final class Clause implements Stringable * * @var array>|null */ - public $impossibilities; + public ?array $impossibilities = null; - /** @var bool */ - public $wedge; + public bool $wedge; public bool $reconcilable; diff --git a/src/Psalm/Internal/Diff/ClassStatementsDiffer.php b/src/Psalm/Internal/Diff/ClassStatementsDiffer.php index 05b3bb4ab04..129ee983681 100644 --- a/src/Psalm/Internal/Diff/ClassStatementsDiffer.php +++ b/src/Psalm/Internal/Diff/ClassStatementsDiffer.php @@ -8,9 +8,7 @@ use UnexpectedValueException; use function count; -use function get_class; use function is_string; -use function strpos; use function str_contains; use function strtolower; use function substr; diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php index 83715df28df..edf35f8b169 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php @@ -299,7 +299,7 @@ static function ($keyed_type) use ($statements_source, $context) { $assertions = Algebra::getTruthsFromFormula( $filter_clauses, - $cond_object_id + $cond_object_id, ); if (isset($assertions['$' . $first_param->var->name])) { diff --git a/src/Psalm/Internal/Scope/IfScope.php b/src/Psalm/Internal/Scope/IfScope.php index 27ea2537249..955aaffdf03 100644 --- a/src/Psalm/Internal/Scope/IfScope.php +++ b/src/Psalm/Internal/Scope/IfScope.php @@ -67,7 +67,7 @@ final class IfScope /** * @var list */ - public $negated_clauses = []; + public array $negated_clauses = []; /** * These are the set of clauses that could be applied after the `if` @@ -76,7 +76,7 @@ final class IfScope * * @var list */ - public $reasonable_clauses = []; + public array $reasonable_clauses = []; /** * @var string[] @@ -88,8 +88,5 @@ final class IfScope */ public array $final_actions = []; - /** - * @var ?Context - */ - public $post_leaving_if_context; + public ?Context $post_leaving_if_context = null; } diff --git a/src/Psalm/Internal/Scope/SwitchScope.php b/src/Psalm/Internal/Scope/SwitchScope.php index 2e4d6a275c7..37d216da92a 100644 --- a/src/Psalm/Internal/Scope/SwitchScope.php +++ b/src/Psalm/Internal/Scope/SwitchScope.php @@ -43,10 +43,10 @@ final class SwitchScope /** * @var list */ - public $negated_clauses = []; + public array $negated_clauses = []; /** * @var array|null */ - public $new_assigned_var_ids; + public ?array $new_assigned_var_ids = null; } diff --git a/src/Psalm/Issue/LiteralKeyUnshapedArray.php b/src/Psalm/Issue/LiteralKeyUnshapedArray.php index 048a959e8a1..2cef46aae0e 100644 --- a/src/Psalm/Issue/LiteralKeyUnshapedArray.php +++ b/src/Psalm/Issue/LiteralKeyUnshapedArray.php @@ -1,5 +1,7 @@ calculateNegation(); $a2 = new IsIsset(); @@ -255,7 +255,7 @@ public function testGroupImpossibilities(): void false, true, true, - [] + [], ))->calculateNegation(); $result_clauses = Algebra::groupImpossibilities([$clause1, $clause2]);