diff --git a/src/Psalm/CodeLocation.php b/src/Psalm/CodeLocation.php index e9041cffb2e..5426c0bfbb6 100644 --- a/src/Psalm/CodeLocation.php +++ b/src/Psalm/CodeLocation.php @@ -51,8 +51,6 @@ class CodeLocation protected int $file_end; - protected bool $single_line; - protected int $preview_start; private int $preview_end = -1; @@ -67,20 +65,12 @@ class CodeLocation private string $snippet = ''; - private ?string $text = null; - public ?int $docblock_start = null; private ?int $docblock_start_line_number = null; - protected ?int $docblock_line_number = null; - - private ?int $regex_type = null; - private bool $have_recalculated = false; - public ?CodeLocation $previous_location = null; - public const VAR_TYPE = 0; public const FUNCTION_RETURN_TYPE = 1; public const FUNCTION_PARAM_TYPE = 2; @@ -119,11 +109,11 @@ class CodeLocation public function __construct( FileSource $file_source, PhpParser\Node $stmt, - ?CodeLocation $previous_location = null, - bool $single_line = false, - ?int $regex_type = null, - ?string $selected_text = null, - ?int $comment_line = null, + public ?CodeLocation $previous_location = null, + protected bool $single_line = false, + private ?int $regex_type = null, + private ?string $text = null, + protected ?int $docblock_line_number = null, ) { /** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */ $this->file_start = (int)$stmt->getAttribute('startFilePos'); @@ -133,10 +123,6 @@ public function __construct( $this->raw_file_end = $this->file_end; $this->file_path = $file_source->getFilePath(); $this->file_name = $file_source->getFileName(); - $this->single_line = $single_line; - $this->regex_type = $regex_type; - $this->previous_location = $previous_location; - $this->text = $selected_text; /** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */ $doc_comment = $stmt->getDocComment(); @@ -148,8 +134,6 @@ public function __construct( /** @psalm-suppress ImpureMethodCall Actually mutation-free just not marked */ $this->raw_line_number = $stmt->getStartLine(); - - $this->docblock_line_number = $comment_line; } /** diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 7e13e4f1727..288de79102a 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -1749,7 +1749,7 @@ public function filterCompletionItemsByBeginLiteralPart(array $items, string $li $res = []; foreach ($items as $item) { - if ($item->insertText && strpos($item->insertText, $literal_part) === 0) { + if ($item->insertText && str_starts_with($item->insertText, $literal_part)) { $res[] = $item; } } diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index a51fe77de12..15d3959c8cc 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -1166,13 +1166,13 @@ private static function fromXmlAndPaths( } if ($paths_to_check !== null) { - $paths_to_add_to_project_files = array(); + $paths_to_add_to_project_files = []; foreach ($paths_to_check as $path) { // if we have an .xml arg here, the files passed are invalid // valid cases (in which we don't want to add CLI passed files to projectFiles though) // are e.g. if running phpunit tests for psalm itself - if (substr($path, -4) === '.xml') { - $paths_to_add_to_project_files = array(); + if (str_ends_with($path, '.xml')) { + $paths_to_add_to_project_files = []; break; } @@ -1195,14 +1195,14 @@ private static function fromXmlAndPaths( $paths_to_add_to_project_files[] = $prospective_path; } - if ($paths_to_add_to_project_files !== array() && !isset($config_xml->projectFiles)) { + if ($paths_to_add_to_project_files !== [] && !isset($config_xml->projectFiles)) { if ($config_xml === null) { $config_xml = new SimpleXMLElement(''); } $config_xml->addChild('projectFiles'); } - if ($paths_to_add_to_project_files !== array() && isset($config_xml->projectFiles)) { + if ($paths_to_add_to_project_files !== [] && isset($config_xml->projectFiles)) { foreach ($paths_to_add_to_project_files as $path) { if (is_dir($path)) { $child = $config_xml->projectFiles->addChild('directory'); @@ -2201,7 +2201,7 @@ public function visitPreloadedStubFiles(Codebase $codebase, ?Progress $progress foreach ($stub_files as $file_path) { $file_path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file_path); // fix mangled phar paths on Windows - if (strpos($file_path, 'phar:\\\\') === 0) { + if (str_starts_with($file_path, 'phar:\\\\')) { $file_path = 'phar://'. substr($file_path, 7); } $codebase->scanner->addFileToDeepScan($file_path); @@ -2290,7 +2290,7 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null): foreach ($stub_files as $file_path) { $file_path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $file_path); // fix mangled phar paths on Windows - if (strpos($file_path, 'phar:\\\\') === 0) { + if (str_starts_with($file_path, 'phar:\\\\')) { $file_path = 'phar://' . substr($file_path, 7); } $codebase->scanner->addFileToDeepScan($file_path); diff --git a/src/Psalm/FileBasedPluginAdapter.php b/src/Psalm/FileBasedPluginAdapter.php index e6aef73fcc8..8a22a7863f1 100644 --- a/src/Psalm/FileBasedPluginAdapter.php +++ b/src/Psalm/FileBasedPluginAdapter.php @@ -27,7 +27,7 @@ final class FileBasedPluginAdapter implements PluginEntryPointInterface public function __construct( string $path, private readonly Config $config, - private Codebase $codebase, + private readonly Codebase $codebase, ) { if (!$path) { throw new UnexpectedValueException('$path cannot be empty'); diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 56e60623cd0..078c8403771 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -109,7 +109,7 @@ final class ProjectAnalyzer /** * An object representing everything we know about the code */ - private Codebase $codebase; + private readonly Codebase $codebase; private readonly FileProvider $file_provider; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php index 10d14b45f18..56839f5059b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php @@ -688,7 +688,7 @@ private static function analyzeOperands( && strtolower($non_decimal_type->value) === "decimal\\decimal" ) { $result_type = Type::combineUnionTypes( - new Union([new TNamedObject("Decimal\\Decimal")]), + new Union([new TNamedObject(\Decimal\Decimal::class)]), $result_type, ); } else { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index 34938c5972e..9efd019c84e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -1415,7 +1415,7 @@ private static function verifyCallableInContext( return false; } } - } catch (UnexpectedValueException $e) { + } catch (UnexpectedValueException) { // do nothing } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 0d3b85b57e2..f5dd51a0166 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -1278,7 +1278,7 @@ private static function handleByRefReadonlyArg( try { $declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_property_class); - } catch (InvalidArgumentException $_) { + } catch (InvalidArgumentException) { return; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php index 1007b9d8855..5b3f17cb5ae 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php @@ -637,7 +637,7 @@ private static function taintReturnType( $pattern = trim($pattern); if ($pattern[0] === '[' && $pattern[1] === '^' - && substr($pattern, -1) === ']' + && str_ends_with($pattern, ']') ) { $pattern = substr($pattern, 2, -1); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php index 8e45e6ad925..6b3203ab3ba 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgInfo.php @@ -27,7 +27,7 @@ final class HighOrderFunctionArgInfo */ public function __construct( private readonly string $type, - private FunctionLikeStorage $function_storage, + private readonly FunctionLikeStorage $function_storage, private readonly ?ClassLikeStorage $class_storage = null, ) { } diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 090601ec78d..f1363d24093 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -798,7 +798,7 @@ private function parseStatementDocblock( if ($this->parsed_docblock === null) { try { $this->parsed_docblock = DocComment::parsePreservingLength($docblock, true); - } catch (DocblockParseException $e) { + } catch (DocblockParseException) { // already reported above } } diff --git a/src/Psalm/Internal/Analyzer/TraitAnalyzer.php b/src/Psalm/Internal/Analyzer/TraitAnalyzer.php index 3d65d479008..459726b4073 100644 --- a/src/Psalm/Internal/Analyzer/TraitAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/TraitAnalyzer.php @@ -20,7 +20,7 @@ public function __construct( Trait_ $class, SourceAnalyzer $source, string $fq_class_name, - private Aliases $aliases, + private readonly Aliases $aliases, ) { $this->source = $source; $this->file_analyzer = $source->getFileAnalyzer(); diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index 90cebe3f301..1b0f2084d71 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -1241,7 +1241,7 @@ private static function getHelpText(): string $formats = []; /** @var string $value */ foreach ((new ReflectionClass(Report::class))->getConstants() as $constant => $value) { - if (strpos($constant, 'TYPE_') === 0) { + if (str_starts_with($constant, 'TYPE_')) { $formats[] = $value; } } diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 3e76494acae..a5d5e977ab3 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -289,11 +289,7 @@ public static function getPathsToCheck(string|array|false|null $f_paths): ?array if (str_starts_with($input_path, '--') && strlen($input_path) > 2) { // ignore --config psalm.xml // ignore common phpunit args that accept a class instead of a path, as this can cause issues on Windows - $ignored_arguments = array( - 'config', - 'printer', - 'root', - ); + $ignored_arguments = ['config', 'printer', 'root']; if (in_array(substr($input_path, 2), $ignored_arguments, true)) { ++$i; diff --git a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php index 9418d6a3e88..61c68b037d5 100644 --- a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php +++ b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php @@ -299,7 +299,7 @@ public static function getCallablesFromCallMap(string $function_id): ?array // removes `rw_` leftover from `&rw_haystack` or `&rw_needle` or `&rw_actual_name` // it doesn't have any specific meaning apart from `&` signifying that // the parameter is passed by reference (handled above) - if ($by_reference && strlen($arg_name) > 3 && strpos($arg_name, 'rw_') === 0) { + if ($by_reference && strlen($arg_name) > 3 && str_starts_with($arg_name, 'rw_')) { $arg_name = substr($arg_name, 3); } diff --git a/src/Psalm/Internal/Codebase/Populator.php b/src/Psalm/Internal/Codebase/Populator.php index 4093c263db5..f00e45fa50e 100644 --- a/src/Psalm/Internal/Codebase/Populator.php +++ b/src/Psalm/Internal/Codebase/Populator.php @@ -52,7 +52,7 @@ final class Populator private array $invalid_class_storages = []; public function __construct( - private ClassLikeStorageProvider $classlike_storage_provider, + private readonly ClassLikeStorageProvider $classlike_storage_provider, private readonly FileStorageProvider $file_storage_provider, private readonly ClassLikes $classlikes, private readonly FileReferenceProvider $file_reference_provider, diff --git a/src/Psalm/Internal/Codebase/TaintFlowGraph.php b/src/Psalm/Internal/Codebase/TaintFlowGraph.php index ddd366476ff..88b02d3169e 100644 --- a/src/Psalm/Internal/Codebase/TaintFlowGraph.php +++ b/src/Psalm/Internal/Codebase/TaintFlowGraph.php @@ -315,177 +315,122 @@ private function getChildNodes( . ' -> ' . $this->getSuccessorPath($sinks[$to_id]); foreach ($matching_taints as $matching_taint) { - switch ($matching_taint) { - case TaintKind::INPUT_CALLABLE: - $issue = new TaintedCallable( - 'Detected tainted text', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_UNSERIALIZE: - $issue = new TaintedUnserialize( - 'Detected tainted code passed to unserialize or similar', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_INCLUDE: - $issue = new TaintedInclude( - 'Detected tainted code passed to include or similar', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_EVAL: - $issue = new TaintedEval( - 'Detected tainted code passed to eval or similar', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_SQL: - $issue = new TaintedSql( - 'Detected tainted SQL', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_HTML: - $issue = new TaintedHtml( - 'Detected tainted HTML', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_HAS_QUOTES: - $issue = new TaintedTextWithQuotes( - 'Detected tainted text with possible quotes', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_SHELL: - $issue = new TaintedShell( - 'Detected tainted shell code', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::USER_SECRET: - $issue = new TaintedUserSecret( - 'Detected tainted user secret leaking', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::SYSTEM_SECRET: - $issue = new TaintedSystemSecret( - 'Detected tainted system secret leaking', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_SSRF: - $issue = new TaintedSSRF( - 'Detected tainted network request', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_LDAP: - $issue = new TaintedLdap( - 'Detected tainted LDAP request', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_COOKIE: - $issue = new TaintedCookie( - 'Detected tainted cookie', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_FILE: - $issue = new TaintedFile( - 'Detected tainted file handling', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_HEADER: - $issue = new TaintedHeader( - 'Detected tainted header', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_XPATH: - $issue = new TaintedXpath( - 'Detected tainted xpath query', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_SLEEP: - $issue = new TaintedSleep( - 'Detected tainted sleep', - $issue_location, - $issue_trace, - $path, - ); - break; - - case TaintKind::INPUT_EXTRACT: - $issue = new TaintedExtract( - 'Detected tainted extract', - $issue_location, - $issue_trace, - $path, - ); - break; - - default: - $issue = new TaintedCustom( - 'Detected tainted ' . $matching_taint, - $issue_location, - $issue_trace, - $path, - ); - } + $issue = match ($matching_taint) { + TaintKind::INPUT_CALLABLE => new TaintedCallable( + 'Detected tainted text', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_UNSERIALIZE => new TaintedUnserialize( + 'Detected tainted code passed to unserialize or similar', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_INCLUDE => new TaintedInclude( + 'Detected tainted code passed to include or similar', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_EVAL => new TaintedEval( + 'Detected tainted code passed to eval or similar', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_SQL => new TaintedSql( + 'Detected tainted SQL', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_HTML => new TaintedHtml( + 'Detected tainted HTML', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_HAS_QUOTES => new TaintedTextWithQuotes( + 'Detected tainted text with possible quotes', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_SHELL => new TaintedShell( + 'Detected tainted shell code', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::USER_SECRET => new TaintedUserSecret( + 'Detected tainted user secret leaking', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::SYSTEM_SECRET => new TaintedSystemSecret( + 'Detected tainted system secret leaking', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_SSRF => new TaintedSSRF( + 'Detected tainted network request', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_LDAP => new TaintedLdap( + 'Detected tainted LDAP request', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_COOKIE => new TaintedCookie( + 'Detected tainted cookie', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_FILE => new TaintedFile( + 'Detected tainted file handling', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_HEADER => new TaintedHeader( + 'Detected tainted header', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_XPATH => new TaintedXpath( + 'Detected tainted xpath query', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_SLEEP => new TaintedSleep( + 'Detected tainted sleep', + $issue_location, + $issue_trace, + $path, + ), + TaintKind::INPUT_EXTRACT => new TaintedExtract( + 'Detected tainted extract', + $issue_location, + $issue_trace, + $path, + ), + default => new TaintedCustom( + 'Detected tainted ' . $matching_taint, + $issue_location, + $issue_trace, + $path, + ), + }; IssueBuffer::maybeAdd($issue); } diff --git a/src/Psalm/Internal/Json/Json.php b/src/Psalm/Internal/Json/Json.php index d5b4c91016c..e4964b75014 100644 --- a/src/Psalm/Internal/Json/Json.php +++ b/src/Psalm/Internal/Json/Json.php @@ -89,7 +89,7 @@ private static function scrub(array $data): array * @psalm-pure * @param mixed $value */ - function (&$value): void { + function (mixed &$value): void { if (is_string($value)) { $value = preg_replace_callback( self::INVALID_UTF_REGEXP, diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index 5e08fac513f..6a503023079 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -97,7 +97,7 @@ final class ClassLikeNodeScanner { private readonly string $file_path; - private Config $config; + private readonly Config $config; /** * @var array @@ -120,7 +120,7 @@ public function __construct( private readonly Codebase $codebase, private readonly FileStorage $file_storage, private readonly FileScanner $file_scanner, - private Aliases $aliases, + private readonly Aliases $aliases, private readonly ?Name $namespace_name, ) { $this->file_path = $file_storage->file_path; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index 1f1e6a403a4..08e97ccda1a 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -87,7 +87,7 @@ public function __construct( private readonly FileStorage $file_storage, private readonly Aliases $aliases, private readonly array $type_aliases, - private ?ClassLikeStorage $classlike_storage, + private readonly ?ClassLikeStorage $classlike_storage, private readonly array $existing_function_template_types, ) { $this->file_path = $file_storage->file_path; diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index b22cb9fc7fc..c9ba8ba45ba 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -54,7 +54,7 @@ final class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements Fi { private Aliases $aliases; - private string $file_path; + private readonly string $file_path; private readonly bool $scan_deep; @@ -88,7 +88,7 @@ final class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements Fi /** * @var SplObjectStorage */ - private SplObjectStorage $closure_statements; + private readonly SplObjectStorage $closure_statements; public function __construct( private readonly Codebase $codebase, diff --git a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php index fefb161bce5..1721696a01f 100644 --- a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php @@ -50,14 +50,11 @@ class FileReferenceCacheProvider private const FILE_MISSING_MEMBER_CACHE_NAME = 'file_missing_member'; private const UNKNOWN_MEMBER_CACHE_NAME = 'unknown_member_references'; private const METHOD_PARAM_USE_CACHE_NAME = 'method_param_uses'; - - protected Config $config; protected Cache $cache; - public function __construct(Config $config) + public function __construct(protected Config $config) { - $this->config = $config; - $this->cache = new Cache($config); + $this->cache = new Cache($this->config); } public function hasConfigChanged(): bool diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php index 9268d932b77..b5096323ecb 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php @@ -175,7 +175,7 @@ static function ($keyed_type) use ($statements_source, $context) { $statements_source, ); - $mapping_function_ids = array(); + $mapping_function_ids = []; if ($callable_extended_var_id) { $possibly_function_ids = $context->vars_in_scope[$callable_extended_var_id] ?? null; // @todo for array callables @@ -189,9 +189,9 @@ static function ($keyed_type) use ($statements_source, $context) { if ($function_call_arg->value instanceof PhpParser\Node\Scalar\String_ || $function_call_arg->value instanceof PhpParser\Node\Expr\Array_ || $function_call_arg->value instanceof PhpParser\Node\Expr\BinaryOp\Concat - || $mapping_function_ids !== array() + || $mapping_function_ids !== [] ) { - if ($mapping_function_ids === array()) { + if ($mapping_function_ids === []) { $mapping_function_ids = CallAnalyzer::getFunctionIdsFromCallableArg( $statements_source, $function_call_arg->value, diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/FilterInputReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/FilterInputReturnTypeProvider.php index 0ab9e045b88..35097f61fcf 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/FilterInputReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/FilterInputReturnTypeProvider.php @@ -161,13 +161,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return $fails_or_not_set_type; } - $possible_types = array( - '$_GET' => INPUT_GET, - '$_POST' => INPUT_POST, - '$_COOKIE' => INPUT_COOKIE, - '$_SERVER' => INPUT_SERVER, - '$_ENV' => INPUT_ENV, - ); + $possible_types = ['$_GET' => INPUT_GET, '$_POST' => INPUT_POST, '$_COOKIE' => INPUT_COOKIE, '$_SERVER' => INPUT_SERVER, '$_ENV' => INPUT_ENV]; $first_arg_type_type = $first_arg_type->getSingleIntLiteral(); $global_name = array_search($first_arg_type_type->value, $possible_types); @@ -211,7 +205,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev } if (FilterUtils::hasFlag($flags_int_used, FILTER_REQUIRE_ARRAY) - && in_array($first_arg_type_type->value, array(INPUT_COOKIE, INPUT_SERVER, INPUT_ENV), true)) { + && in_array($first_arg_type_type->value, [INPUT_COOKIE, INPUT_SERVER, INPUT_ENV], true)) { // these globals can never be an array return $fails_or_not_set_type; } diff --git a/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php b/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php index de8d509eb13..98164cbfe1a 100644 --- a/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php @@ -124,14 +124,14 @@ public static function isContainedBy( } if ($input_type_part instanceof TCallableString) { - if (get_class($container_type_part) === TNonEmptyString::class - || get_class($container_type_part) === TNonFalsyString::class + if ($container_type_part::class === TNonEmptyString::class + || $container_type_part::class === TNonFalsyString::class ) { return true; } - if (get_class($container_type_part) === TLowercaseString::class - || get_class($container_type_part) === TSingleLetter::class + if ($container_type_part::class === TLowercaseString::class + || $container_type_part::class === TSingleLetter::class ) { if ($atomic_comparison_result) { $atomic_comparison_result->type_coerced = true; diff --git a/src/Psalm/Internal/Type/ParseTreeCreator.php b/src/Psalm/Internal/Type/ParseTreeCreator.php index cbf5fb81800..1c85410395e 100644 --- a/src/Psalm/Internal/Type/ParseTreeCreator.php +++ b/src/Psalm/Internal/Type/ParseTreeCreator.php @@ -832,7 +832,7 @@ private function handleValue(array $type_token): void $nexter_token = $this->t + 1 < $this->type_token_count ? $this->type_tokens[$this->t + 1] : null; if ($nexter_token - && strpos($nexter_token[0], '@') !== false + && str_contains($nexter_token[0], '@') && $type_token[0] !== 'list' && $type_token[0] !== 'array' ) { diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index c8b2f879f56..c84b888e311 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1164,7 +1164,7 @@ private static function scrapeStringProperties( if ($has_empty_string) { $combination->value_types['string'] = new TString(); - } elseif ($has_non_lowercase_string && get_class($type) !== TNonEmptyString::class) { + } elseif ($has_non_lowercase_string && $type::class !== TNonEmptyString::class) { $combination->value_types['string'] = new TNonEmptyString(); } else { $combination->value_types['string'] = $type; @@ -1229,8 +1229,8 @@ private static function scrapeStringProperties( ) ) { // do nothing - } elseif (get_class($type) === TNonspecificLiteralString::class - && get_class($combination->value_types['string']) === TNonEmptyNonspecificLiteralString::class + } elseif ($type::class === TNonspecificLiteralString::class + && $combination->value_types['string']::class === TNonEmptyNonspecificLiteralString::class ) { $combination->value_types['string'] = $type; } else { diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index dbcc9242a21..10e686ad58b 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -266,7 +266,7 @@ public static function add(CodeIssue $e, bool $is_fixable = false): bool $project_analyzer = ProjectAnalyzer::getInstance(); $codebase = $project_analyzer->getCodebase(); - $fqcn_parts = explode('\\', get_class($e)); + $fqcn_parts = explode('\\', $e::class); $issue_type = array_pop($fqcn_parts); if (!$project_analyzer->show_issues) { diff --git a/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php b/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php index ed9ed33e5e6..d5d6f6af6fb 100644 --- a/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php +++ b/src/Psalm/Plugin/EventHandler/Event/BeforeFileAnalysisEvent.php @@ -23,7 +23,7 @@ public function __construct( private readonly Context $file_context, private readonly FileStorage $file_storage, private readonly Codebase $codebase, - private array $stmts, + private readonly array $stmts, ) { } diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index 8d2393d0dc7..9c15e14f580 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -919,7 +919,7 @@ private static function intersectAtomicTypes( ) { return $intersection_atomic; } - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { // Ignore non-existing classes during initial scan } } diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index e31b828dece..69dcac35a43 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -1153,7 +1153,7 @@ private static function adjustTKeyedArrayType( ; } - $base_key = implode($key_parts); + $base_key = implode('', $key_parts); $result_type = $result_type->setPossiblyUndefined( $result_type->possibly_undefined || count($array_key_offsets) > 1,