diff --git a/dictionaries/scripts/update_signaturemap_from_other_tool.php b/dictionaries/scripts/update_signaturemap_from_other_tool.php index 21fb61166d5..d50e88ee0a8 100644 --- a/dictionaries/scripts/update_signaturemap_from_other_tool.php +++ b/dictionaries/scripts/update_signaturemap_from_other_tool.php @@ -30,7 +30,7 @@ $removed_foreign_functions ); -uksort($new_local, fn($a, $b) => strtolower($a) <=> strtolower($b)); +uksort($new_local, static fn($a, $b) => strtolower($a) <=> strtolower($b)); foreach ($new_local as $name => $data) { if (!is_array($data)) { diff --git a/examples/plugins/ClassUnqualifier.php b/examples/plugins/ClassUnqualifier.php index 3f4f14f517a..57a9f86da08 100644 --- a/examples/plugins/ClassUnqualifier.php +++ b/examples/plugins/ClassUnqualifier.php @@ -44,7 +44,7 @@ public static function afterClassLikeExistenceCheck( $new_candidate_type = implode( '', array_map( - fn($f) => $f[0], + static fn($f) => $f[0], $type_tokens, ), ); diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index d2b5d54ceae..e1c2f017090 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -69,7 +69,6 @@ use UnexpectedValueException; use function array_combine; -use function array_merge; use function array_pop; use function array_reverse; use function array_values; @@ -1917,7 +1916,7 @@ public function getCompletionItemsForClassishThing( ); } - $completion_items = array_merge($completion_items, array_values($pseudo_property_types)); + $completion_items = [...$completion_items, ...array_values($pseudo_property_types)]; foreach ($class_storage->declaring_property_ids as $property_name => $declaring_class) { $property_storage = $this->properties->getStorage( diff --git a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php index 3ee68c6582f..bc20c08f8ae 100644 --- a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php @@ -707,7 +707,7 @@ protected function checkTemplateParams( && $storage->template_types && $storage->template_covariants && ($local_offset - = array_search($t->param_name, array_keys($storage->template_types))) + = array_search($t->param_name, array_keys($storage->template_types), true)) !== false && !empty($storage->template_covariants[$local_offset]) ) { diff --git a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php index 9668f292417..65915d1f34c 100644 --- a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php @@ -25,7 +25,6 @@ use Psalm\Type\Union; use UnexpectedValueException; -use function array_merge; use function count; use function is_string; use function preg_match; @@ -400,7 +399,7 @@ public static function splitDocLine(string $return_block): array $remaining = trim(preg_replace('@^[ \t]*\* *@m', ' ', substr($return_block, $i + 1))); if ($remaining) { - return array_merge([rtrim($type)], preg_split('/\s+/', $remaining) ?: []); + return [rtrim($type), ...preg_split('/\s+/', $remaining) ?: []]; } return [$type]; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index 905dc3d8a80..128eaada6ef 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -1096,7 +1096,7 @@ private static function getExtendedType( ): ?Union { if ($calling_class === $template_class) { if (isset($class_template_types[$template_name]) && $calling_type_params) { - $offset = array_search($template_name, array_keys($class_template_types)); + $offset = array_search($template_name, array_keys($class_template_types), true); if ($offset !== false && isset($calling_type_params[$offset])) { return $calling_type_params[$offset]; 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 fca21662783..5997ac82efa 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php @@ -751,6 +751,7 @@ private static function handleTemplatedMixins( $param_position = array_search( $mixin->param_name, $template_type_keys, + true, ); if ($param_position !== false diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index 12285e2432e..99f045d71c6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -476,7 +476,7 @@ public static function castIntAttempt( // todo: emit error here } - $valid_types = array_merge($valid_ints, $castable_types); + $valid_types = [...$valid_ints, ...$castable_types]; if (!$valid_types) { $int_type = Type::getInt(); @@ -661,7 +661,7 @@ public static function castFloatAttempt( // todo: emit error here } - $valid_types = array_merge($valid_floats, $castable_types); + $valid_types = [...$valid_floats, ...$castable_types]; if (!$valid_types) { $float_type = Type::getFloat(); @@ -804,10 +804,7 @@ public static function castStringAttempt( $parent_nodes = array_merge($return_type->parent_nodes, $parent_nodes); } - $castable_types = array_merge( - $castable_types, - array_values($return_type->getAtomicTypes()), - ); + $castable_types = [...$castable_types, ...array_values($return_type->getAtomicTypes())]; continue 2; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index d6289b6687b..ff14ed24273 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -788,6 +788,7 @@ public static function localizePropertyType( $position = array_search( $param_name, array_keys($property_class_storage->template_types), + true, ); } @@ -1000,7 +1001,7 @@ private static function handleEnumName( empty($relevant_enum_case_names) ? Type::getNonEmptyString() : new Union(array_map( - fn(string $name): TString => Type::getAtomicStringFromLiteral($name), + static fn(string $name): TString => Type::getAtomicStringFromLiteral($name), $relevant_enum_case_names, )), ); diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 55e80d44643..fc75e1631eb 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -869,7 +869,7 @@ public function checkUnreferencedVars(array $stmts, Context $context): void } if ($function_storage) { - $param_index = array_search(substr($var_id, 1), array_keys($function_storage->param_lookup)); + $param_index = array_search(substr($var_id, 1), array_keys($function_storage->param_lookup), true); if ($param_index !== false) { $param = $function_storage->params[$param_index]; diff --git a/src/Psalm/Internal/Codebase/Populator.php b/src/Psalm/Internal/Codebase/Populator.php index 022cc684e46..69aa208044e 100644 --- a/src/Psalm/Internal/Codebase/Populator.php +++ b/src/Psalm/Internal/Codebase/Populator.php @@ -931,10 +931,10 @@ protected function inheritMethodsFromParent( if ($parent_storage->is_trait && $storage->trait_alias_map ) { - $aliased_method_names = array_merge( - $aliased_method_names, - array_keys($storage->trait_alias_map, $method_name_lc, true), - ); + $aliased_method_names = [ + ...$aliased_method_names, + ...array_keys($storage->trait_alias_map, $method_name_lc, true), + ]; } foreach ($aliased_method_names as $aliased_method_name) { @@ -1001,10 +1001,10 @@ protected function inheritMethodsFromParent( if ($parent_storage->is_trait && $storage->trait_alias_map ) { - $aliased_method_names = array_merge( - $aliased_method_names, - array_keys($storage->trait_alias_map, $method_name_lc, true), - ); + $aliased_method_names = [ + ...$aliased_method_names, + ...array_keys($storage->trait_alias_map, $method_name_lc, true), + ]; } foreach ($aliased_method_names as $aliased_method_name) { diff --git a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php index b04952c0581..f10a42379e2 100644 --- a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php +++ b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php @@ -44,7 +44,7 @@ class FunctionDocblockManipulator private static array $manipulators = []; /** @var Closure|Function_|ClassMethod|ArrowFunction */ - private $stmt; + private FunctionLike $stmt; private int $docblock_start; @@ -415,7 +415,7 @@ private function getDocblock(): string $modified_docblock = true; $inferredThrowsClause = array_reduce( $this->throwsExceptions, - fn(string $throwsClause, string $exception) => $throwsClause === '' + static fn(string $throwsClause, string $exception) => $throwsClause === '' ? $exception : $throwsClause.'|'.$exception, '', diff --git a/src/Psalm/Internal/LanguageServer/LanguageServer.php b/src/Psalm/Internal/LanguageServer/LanguageServer.php index ed6b879dcbe..fde6b541395 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageServer.php +++ b/src/Psalm/Internal/LanguageServer/LanguageServer.php @@ -237,7 +237,7 @@ function (Message $msg): Generator { $this->protocolReader->on( 'readMessageGroup', - function (): void { + static function (): void { //$this->verboseLog('Received message group'); //$this->doAnalysis(); }, @@ -765,7 +765,7 @@ function (IssueData $issue_data): Diagnostic { return $diagnostic; }, array_filter( - array_map(function (IssueData $issue_data) use (&$issue_baseline) { + array_map(static function (IssueData $issue_data) use (&$issue_baseline) { if (empty($issue_baseline)) { return $issue_data; } diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php index 92397ebb69f..910c5d5c9e6 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php @@ -113,9 +113,9 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev $array_arg_types = array_map(null, ...$array_arg_types); $array_arg_types = array_map( /** @param non-empty-array $sub */ - function (array $sub) use ($null) { + static function (array $sub) use ($null) { $sub = array_map( - fn(?Union $t) => $t ?? $null, + static fn(?Union $t) => $t ?? $null, $sub, ); return new Union([new TKeyedArray($sub, null, null, true)]); diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index 5e0d0a827ed..aa606ec8f89 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -686,7 +686,7 @@ private static function reconcileNonEmptyCountable( $existing_var_type->removeType('array'); $existing_var_type->addType($array_atomic_type->setProperties( array_map( - fn(Union $union) => $union->setPossiblyUndefined(false), + static fn(Union $union) => $union->setPossiblyUndefined(false), $array_atomic_type->properties, ), )); @@ -806,7 +806,7 @@ private static function reconcileExactlyCountable( $existing_var_type->removeType('array'); $existing_var_type->addType($array_atomic_type->setProperties( array_map( - fn(Union $union) => $union->setPossiblyUndefined(false), + static fn(Union $union) => $union->setPossiblyUndefined(false), $array_atomic_type->properties, ), )); diff --git a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php index fc8573ab418..259aedd9521 100644 --- a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php @@ -226,7 +226,7 @@ public static function replace( )->freeze(); } - $atomic_types = array_merge($types, $new_types); + $atomic_types = [...$types, ...$new_types]; if (!$atomic_types) { throw new UnexpectedValueException('This array should be full'); } diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index 9fa51c420cd..bbab4e24b7b 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -1343,6 +1343,7 @@ public static function getMappedGenericTypeParams( $old_params_offset = (int) array_search( $template->param_name, array_keys($input_class_storage->template_types), + true, ); $candidate_param_types[] = ($input_type_params[$old_params_offset] ?? Type::getMixed()) diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 99cf82a4d51..0287ab4d6bd 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -958,7 +958,11 @@ private static function getTypeFromGenericTree( } assert(count($parse_tree->children) === 2); - $get_int_range_bound = function (ParseTree $parse_tree, Union $generic_param, string $bound_name): ?int { + $get_int_range_bound = static function ( + ParseTree $parse_tree, + Union $generic_param, + string $bound_name + ): ?int { if (!$parse_tree instanceof Value || count($generic_param->getAtomicTypes()) > 1 || (!$generic_param->getSingleAtomic() instanceof TLiteralInt @@ -970,7 +974,6 @@ private static function getTypeFromGenericTree( "Invalid type \"{$generic_param->getId()}\" as int $bound_name boundary", ); } - $generic_param_atomic = $generic_param->getSingleAtomic(); return $generic_param_atomic instanceof TLiteralInt ? $generic_param_atomic->value : null; }; diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 1460c53f7c8..9ca29ef701b 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -190,7 +190,7 @@ public static function isSuppressed(CodeIssue $e, array $suppressed_issues = []) return true; } - $suppressed_issue_position = array_search($issue_type, $suppressed_issues); + $suppressed_issue_position = array_search($issue_type, $suppressed_issues, true); if ($suppressed_issue_position !== false) { if (is_int($suppressed_issue_position)) { @@ -203,7 +203,7 @@ public static function isSuppressed(CodeIssue $e, array $suppressed_issues = []) $parent_issue_type = Config::getParentIssueType($issue_type); if ($parent_issue_type) { - $suppressed_issue_position = array_search($parent_issue_type, $suppressed_issues); + $suppressed_issue_position = array_search($parent_issue_type, $suppressed_issues, true); if ($suppressed_issue_position !== false) { if (is_int($suppressed_issue_position)) { @@ -216,7 +216,7 @@ public static function isSuppressed(CodeIssue $e, array $suppressed_issues = []) $suppress_all_position = $config->disable_suppress_all ? false - : array_search('all', $suppressed_issues); + : array_search('all', $suppressed_issues, true); if ($suppress_all_position !== false) { if (is_int($suppress_all_position)) { diff --git a/src/Psalm/Plugin/EventHandler/Event/AfterMethodCallAnalysisEvent.php b/src/Psalm/Plugin/EventHandler/Event/AfterMethodCallAnalysisEvent.php index b0ad1ef31d5..f699a6d4e03 100644 --- a/src/Psalm/Plugin/EventHandler/Event/AfterMethodCallAnalysisEvent.php +++ b/src/Psalm/Plugin/EventHandler/Event/AfterMethodCallAnalysisEvent.php @@ -16,7 +16,7 @@ final class AfterMethodCallAnalysisEvent /** * @var MethodCall|StaticCall */ - private $expr; + private Expr $expr; private string $method_id; private string $appearing_method_id; private string $declaring_method_id; diff --git a/src/Psalm/Report/ByIssueLevelAndTypeReport.php b/src/Psalm/Report/ByIssueLevelAndTypeReport.php index c657b415749..36aeb60221b 100644 --- a/src/Psalm/Report/ByIssueLevelAndTypeReport.php +++ b/src/Psalm/Report/ByIssueLevelAndTypeReport.php @@ -181,7 +181,7 @@ private function sortIssuesByLevelAndType(): void { usort( $this->issues_data, - fn(IssueData $left, IssueData $right): int => [$left->error_level > 0, -$left->error_level, + static fn(IssueData $left, IssueData $right): int => [$left->error_level > 0, -$left->error_level, $left->type, $left->file_path, $left->file_name, $left->line_from] <=> [$right->error_level > 0, -$right->error_level, $right->type, $right->file_path, $right->file_name, $right->line_from], diff --git a/src/Psalm/Report/CountReport.php b/src/Psalm/Report/CountReport.php index b044d851651..4321789d44b 100644 --- a/src/Psalm/Report/CountReport.php +++ b/src/Psalm/Report/CountReport.php @@ -21,7 +21,7 @@ public function create(): string $issue_type_counts[$issue_data->type] = 1; } } - uksort($issue_type_counts, function (string $a, string $b) use ($issue_type_counts): int { + uksort($issue_type_counts, static function (string $a, string $b) use ($issue_type_counts): int { $cmp_result = $issue_type_counts[$a] <=> $issue_type_counts[$b]; if ($cmp_result === 0) { return $a <=> $b; diff --git a/src/Psalm/Storage/FunctionLikeStorage.php b/src/Psalm/Storage/FunctionLikeStorage.php index 929e2b84d7a..7be91f80434 100644 --- a/src/Psalm/Storage/FunctionLikeStorage.php +++ b/src/Psalm/Storage/FunctionLikeStorage.php @@ -254,7 +254,7 @@ public function getHoverMarkdown(): string $params = count($this->params) > 0 ? "\n" . implode( ",\n", array_map( - function (FunctionLikeParameter $param): string { + static function (FunctionLikeParameter $param): string { $realType = $param->type ?: 'mixed'; return " {$realType} \${$param->name}"; }, @@ -289,7 +289,7 @@ public function getCompletionSignature(): string $symbol_text = 'function ' . $this->cased_name . '(' . implode( ',', array_map( - fn(FunctionLikeParameter $param): string => ($param->type ?: 'mixed') . ' $' . $param->name, + static fn(FunctionLikeParameter $param): string => ($param->type ?: 'mixed') . ' $' . $param->name, $this->params, ), ) . ') : ' . ($this->return_type ?: 'mixed'); diff --git a/src/Psalm/Type/Atomic/TClosure.php b/src/Psalm/Type/Atomic/TClosure.php index 97949adc967..94ee9446d44 100644 --- a/src/Psalm/Type/Atomic/TClosure.php +++ b/src/Psalm/Type/Atomic/TClosure.php @@ -9,8 +9,6 @@ use Psalm\Type\Atomic; use Psalm\Type\Union; -use function array_merge; - /** * Represents a closure where we know the return type and params * @@ -131,6 +129,6 @@ public function replaceTemplateTypesWithStandins( protected function getChildNodeKeys(): array { - return array_merge(parent::getChildNodeKeys(), $this->getCallableChildNodeKeys()); + return [...parent::getChildNodeKeys(), ...$this->getCallableChildNodeKeys()]; } } diff --git a/src/Psalm/Type/Atomic/TGenericObject.php b/src/Psalm/Type/Atomic/TGenericObject.php index 45aa50b8cee..c362085f565 100644 --- a/src/Psalm/Type/Atomic/TGenericObject.php +++ b/src/Psalm/Type/Atomic/TGenericObject.php @@ -8,7 +8,6 @@ use Psalm\Type\Atomic; use Psalm\Type\Union; -use function array_merge; use function count; use function implode; use function strrpos; @@ -127,7 +126,7 @@ public function getAssertionString(): string protected function getChildNodeKeys(): array { - return array_merge(parent::getChildNodeKeys(), ['type_params']); + return [...parent::getChildNodeKeys(), 'type_params']; } /** diff --git a/src/Psalm/Type/Atomic/TValueOf.php b/src/Psalm/Type/Atomic/TValueOf.php index 9220c079dee..59941bc61e5 100644 --- a/src/Psalm/Type/Atomic/TValueOf.php +++ b/src/Psalm/Type/Atomic/TValueOf.php @@ -42,8 +42,9 @@ private static function getValueTypeForNamedObject(array $cases, TNamedObject $a } return new Union(array_map( - function (EnumCaseStorage $case): Atomic { - assert($case->value !== null); // Backed enum must have a value + static function (EnumCaseStorage $case): Atomic { + assert($case->value !== null); + // Backed enum must have a value return ConstantTypeResolver::getLiteralTypeFromScalarValue($case->value); }, array_values($cases), diff --git a/src/Psalm/Type/UnionTrait.php b/src/Psalm/Type/UnionTrait.php index 3361c2ba873..a500789cf41 100644 --- a/src/Psalm/Type/UnionTrait.php +++ b/src/Psalm/Type/UnionTrait.php @@ -43,7 +43,6 @@ use Psalm\Type\Atomic\TTrue; use function array_filter; -use function array_merge; use function array_unique; use function count; use function get_class; @@ -273,13 +272,13 @@ public function toNamespacedString( } if (count($literal_ints) <= 3 && !$has_non_literal_int) { - $other_types = array_merge($other_types, $literal_ints); + $other_types = [...$other_types, ...$literal_ints]; } else { $other_types[] = 'int'; } if (count($literal_strings) <= 3 && !$has_non_literal_string) { - $other_types = array_merge($other_types, $literal_strings); + $other_types = [...$other_types, ...$literal_strings]; } else { $other_types[] = 'string'; } diff --git a/tests/AsyncTestCase.php b/tests/AsyncTestCase.php index e9834d7af89..b459c42414b 100644 --- a/tests/AsyncTestCase.php +++ b/tests/AsyncTestCase.php @@ -152,7 +152,7 @@ public static function assertArrayKeysAreStrings(array $array, string $message = */ public static function assertArrayKeysAreZeroOrString(array $array, string $message = ''): void { - $isZeroOrString = /** @param mixed $key */ fn($key): bool => $key === 0 || is_string($key); + $isZeroOrString = /** @param mixed $key */ static fn($key): bool => $key === 0 || is_string($key); $validKeys = array_filter($array, $isZeroOrString, ARRAY_FILTER_USE_KEY); self::assertTrue(count($array) === count($validKeys), $message); } diff --git a/tests/CodebaseTest.php b/tests/CodebaseTest.php index 81e7a7786b8..f5291649826 100644 --- a/tests/CodebaseTest.php +++ b/tests/CodebaseTest.php @@ -159,7 +159,7 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) ? (string)$stmt->extends->getAttribute('resolvedName') : ''; $storage->custom_metadata['implements'] = array_map( - fn(Name $aspect): string => (string)$aspect->getAttribute('resolvedName'), + static fn(Name $aspect): string => (string)$aspect->getAttribute('resolvedName'), $stmt->implements, ); $storage->custom_metadata['a'] = 'b'; diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 17d6a2e5c5e..88273122b36 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -1106,7 +1106,7 @@ public function testAllPossibleIssues(): void * @param string $issue_name * @return string */ - fn($issue_name): string => '<' . $issue_name . ' errorLevel="suppress" />' . "\n", + static fn($issue_name): string => '<' . $issue_name . ' errorLevel="suppress" />' . "\n", IssueHandler::getAllIssueTypes(), ), ); diff --git a/tests/Config/Plugin/Hook/CustomArrayMapFunctionStorageProvider.php b/tests/Config/Plugin/Hook/CustomArrayMapFunctionStorageProvider.php index a491d9ecf1b..87da0a93636 100644 --- a/tests/Config/Plugin/Hook/CustomArrayMapFunctionStorageProvider.php +++ b/tests/Config/Plugin/Hook/CustomArrayMapFunctionStorageProvider.php @@ -54,11 +54,10 @@ public static function getFunctionStorage(DynamicFunctionStorageProviderEvent $e $custom_array_map_storage->return_type = self::createReturnType($all_expected_callables); $custom_array_map_storage->params = [ ...array_map( - function (TCallable $expected, int $offset) { + static function (TCallable $expected, int $offset) { $t = new Union([$expected]); $param = new FunctionLikeParameter('fn' . $offset, false, $t, $t); $param->is_optional = false; - return $param; }, $all_expected_callables, diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index 653e25f2004..26b734c803a 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -342,7 +342,7 @@ public function testShortcodesAreUnique(): void $duplicate_shortcodes = array_filter( $all_shortcodes, - fn($issues): bool => count($issues) > 1 + static fn($issues): bool => count($issues) > 1 ); $this->assertEquals( diff --git a/tests/FileDiffTest.php b/tests/FileDiffTest.php index acc84f404bb..345e1d98b3b 100644 --- a/tests/FileDiffTest.php +++ b/tests/FileDiffTest.php @@ -62,7 +62,7 @@ public function testCode( * @param array{0: int, 1: int, 2: int, 3: int} $arr * @return array{0: int, 1: int} */ - fn(array $arr): array => [$arr[2], $arr[3]], + static fn(array $arr): array => [$arr[2], $arr[3]], $diff[3], ); @@ -133,7 +133,7 @@ public function testPartialAstDiff( * @param array{0: int, 1: int, 2: int, 3: int} $arr * @return array{0: int, 1: int} */ - fn(array $arr): array => [$arr[2], $arr[3]], + static fn(array $arr): array => [$arr[2], $arr[3]], $diff[3], ); diff --git a/tests/TaintTest.php b/tests/TaintTest.php index faa299957d4..9f62160edb2 100644 --- a/tests/TaintTest.php +++ b/tests/TaintTest.php @@ -2528,7 +2528,7 @@ public function multipleTaintIssuesAreDetected(string $code, array $expectedIssu $this->analyzeFile($filePath, new Context(), false); $actualIssueTypes = array_map( - fn(IssueData $issue): string => $issue->type . '{ ' . trim($issue->snippet) . ' }', + static fn(IssueData $issue): string => $issue->type . '{ ' . trim($issue->snippet) . ' }', IssueBuffer::getIssuesDataForFile($filePath), ); self::assertSame($expectedIssuesTypes, $actualIssueTypes); diff --git a/tests/TestCase.php b/tests/TestCase.php index 00739cbccb0..d0d285eb9e3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -149,7 +149,7 @@ public static function assertArrayKeysAreStrings(array $array, string $message = public static function assertArrayKeysAreZeroOrString(array $array, string $message = ''): void { - $isZeroOrString = /** @param mixed $key */ fn($key): bool => $key === 0 || is_string($key); + $isZeroOrString = /** @param mixed $key */ static fn($key): bool => $key === 0 || is_string($key); $validKeys = array_filter($array, $isZeroOrString, ARRAY_FILTER_USE_KEY); self::assertTrue(count($array) === count($validKeys), $message); } diff --git a/tests/TypeComparatorTest.php b/tests/TypeComparatorTest.php index 6a2d093f511..0e21e5e7880 100644 --- a/tests/TypeComparatorTest.php +++ b/tests/TypeComparatorTest.php @@ -88,7 +88,7 @@ public function getAllBasicTypes(): array $basic_types['list{123}'] = true; return array_map( - fn($type) => [$type], + static fn($type) => [$type], array_keys($basic_types), ); } diff --git a/tests/fixtures/DestructiveAutoloader/autoloader.php b/tests/fixtures/DestructiveAutoloader/autoloader.php index 17cb0a152c5..37a8624de36 100644 --- a/tests/fixtures/DestructiveAutoloader/autoloader.php +++ b/tests/fixtures/DestructiveAutoloader/autoloader.php @@ -9,7 +9,7 @@ $GLOBALS[$key] = new Exception; } -spl_autoload_register(function() { +spl_autoload_register(static function () { // and destroy vars again // this will run during scanning (?) foreach ($GLOBALS as $key => $_) { diff --git a/tests/fixtures/SuicidalAutoloader/autoloader.php b/tests/fixtures/SuicidalAutoloader/autoloader.php index 365fa7b723e..d506219c141 100644 --- a/tests/fixtures/SuicidalAutoloader/autoloader.php +++ b/tests/fixtures/SuicidalAutoloader/autoloader.php @@ -3,7 +3,7 @@ use React\Promise\PromiseInterface as ReactPromise; use Composer\InstalledVersions; -spl_autoload_register(function (string $className) { +spl_autoload_register(static function (string $className) { $knownBadClasses = [ ReactPromise::class, // amphp/amp ResourceBundle::class, // symfony/polyfill-php73 @@ -25,11 +25,9 @@ 'Symfony\Component\String\s', 'Symfony\Component\Translation\t', ]; - if (in_array($className, $knownBadClasses)) { return; } - $ex = new RuntimeException('Attempted to load ' . $className); echo $ex->__toString() . "\n\n" . $ex->getTraceAsString() . "\n\n"; exit(70);