From 966211e0523d2062e78366cd9a1bd726441293ff Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 20:49:51 +0200 Subject: [PATCH 01/33] unused variable --- .../Internal/Analyzer/Statements/Expression/CallAnalyzer.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index 1b94c2abf64..c0412d8b101 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -191,17 +191,12 @@ public static function collectSpecialInformation( || $is_final) ) { $local_vars_in_scope = []; - $local_vars_possibly_in_scope = []; foreach ($context->vars_in_scope as $var_id => $type) { if (strpos($var_id, '$this->') === 0) { if ($type->initialized) { $local_vars_in_scope[$var_id] = $context->vars_in_scope[$var_id]; - if (isset($context->vars_possibly_in_scope[$var_id])) { - $local_vars_possibly_in_scope[$var_id] = $context->vars_possibly_in_scope[$var_id]; - } - unset($context->vars_in_scope[$var_id]); unset($context->vars_possibly_in_scope[$var_id]); } From a03e55a11079f8189a980bb5f094ac655b6b912e Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 20:50:22 +0200 Subject: [PATCH 02/33] array_push misused --- src/Psalm/Internal/Type/TypeTokenizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/TypeTokenizer.php b/src/Psalm/Internal/Type/TypeTokenizer.php index bb74404a2d0..0882000b3ca 100644 --- a/src/Psalm/Internal/Type/TypeTokenizer.php +++ b/src/Psalm/Internal/Type/TypeTokenizer.php @@ -479,7 +479,7 @@ public static function getFullyQualifiedTokens( $replacement_tokens = $type_alias->replacement_tokens; array_unshift($replacement_tokens, ['(', $i]); - array_push($replacement_tokens, [')', $i]); + $replacement_tokens[] = [')', $i]; $diff = count($replacement_tokens) - 1; From c0f6474bc6baa9ec615b62f2528fda0d274a2a27 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 20:54:29 +0200 Subject: [PATCH 03/33] merging exceptions --- .../Analyzer/Statements/Expression/SimpleTypeInferer.php | 4 +--- .../Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php | 7 +------ src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php | 7 +------ 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php index 32398a8e7f4..ceb43a8a5a8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php @@ -282,9 +282,7 @@ public static function infer( } return null; - } catch (\InvalidArgumentException $e) { - return null; - } catch (\Psalm\Exception\CircularReferenceException $e) { + } catch (\InvalidArgumentException | \Psalm\Exception\CircularReferenceException $e) { return null; } } diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index fc933678c53..4d257f5a143 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -366,12 +366,7 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool if ($type_aliases) { $this->classlike_type_aliases = $type_aliases; } - } catch (DocblockParseException $e) { - $storage->docblock_issues[] = new InvalidDocblock( - $e->getMessage(), - new CodeLocation($this->file_scanner, $node, null, true) - ); - } catch (TypeParseTreeException $e) { + } catch (DocblockParseException | TypeParseTreeException $e) { $storage->docblock_issues[] = new InvalidDocblock( $e->getMessage(), new CodeLocation($this->file_scanner, $node, null, true) diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 8c1a4c320dd..3da990b3670 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -145,12 +145,7 @@ public function enterNode(PhpParser\Node $node): ?int } $this->type_aliases += $type_aliases; - } catch (DocblockParseException $e) { - $this->file_storage->docblock_issues[] = new InvalidDocblock( - $e->getMessage(), - new CodeLocation($this->file_scanner, $node, null, true) - ); - } catch (TypeParseTreeException $e) { + } catch (DocblockParseException | TypeParseTreeException $e) { $this->file_storage->docblock_issues[] = new InvalidDocblock( $e->getMessage(), new CodeLocation($this->file_scanner, $node, null, true) From 4481428f97641a87d855f38f167b610ae58b1789 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 20:54:37 +0200 Subject: [PATCH 04/33] unused param --- .../Analyzer/Statements/Expression/BitwiseNotAnalyzer.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php index 74a2e04d389..25e183d9977 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php @@ -100,8 +100,7 @@ public static function analyze( private static function addDataFlow( StatementsAnalyzer $statements_analyzer, PhpParser\Node\Expr $stmt, - PhpParser\Node\Expr $value, - string $type = 'bitwisenot' + PhpParser\Node\Expr $value ): void { $result_type = $statements_analyzer->node_data->getType($stmt); if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph && $result_type) { @@ -109,7 +108,7 @@ private static function addDataFlow( $stmt_value_type = $statements_analyzer->node_data->getType($value); - $new_parent_node = DataFlowNode::getForAssignment($type, $var_location); + $new_parent_node = DataFlowNode::getForAssignment('bitwisenot', $var_location); $statements_analyzer->data_flow_graph->addNode($new_parent_node); $result_type->parent_nodes = [ $new_parent_node->id => $new_parent_node, @@ -117,7 +116,7 @@ private static function addDataFlow( if ($stmt_value_type && $stmt_value_type->parent_nodes) { foreach ($stmt_value_type->parent_nodes as $parent_node) { - $statements_analyzer->data_flow_graph->addPath($parent_node, $new_parent_node, $type); + $statements_analyzer->data_flow_graph->addPath($parent_node, $new_parent_node, 'bitwisenot'); } } } From 153de33704a515d8f03663cb4fcebb9a5cd7d5e1 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 20:56:14 +0200 Subject: [PATCH 05/33] weird param always false --- .../Analyzer/Statements/Expression/AssertionFinder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 2a1b9d4f8c9..61ab1f7b988 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -133,7 +133,7 @@ public static function scrapeAssertions( $this_class_name, $source, $codebase, - false, + false, //should this be $inside_negation?? $cache, $inside_conditional ); @@ -147,7 +147,7 @@ public static function scrapeAssertions( $this_class_name, $source, $codebase, - false, + false, //should this be $inside_negation?? $cache, $inside_conditional ); From b65af9bf2ffd06a6b7a58805cc90d2e50952dfe4 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 21:06:14 +0200 Subject: [PATCH 06/33] static in final class --- src/Psalm/Internal/Composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Composer.php b/src/Psalm/Internal/Composer.php index 16abe536944..52ac9350ac3 100644 --- a/src/Psalm/Internal/Composer.php +++ b/src/Psalm/Internal/Composer.php @@ -35,7 +35,7 @@ public static function getJsonFilePath(string $root): string */ public static function getLockFilePath(string $root): string { - $composer_json_path = static::getJsonFilePath($root); + $composer_json_path = self::getJsonFilePath($root); return "json" === pathinfo($composer_json_path, PATHINFO_EXTENSION) ? substr($composer_json_path, 0, -4).'lock' : $composer_json_path . '.lock'; From fce60a018a16b476b0cb170d86cbda5befa0969a Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 21:09:20 +0200 Subject: [PATCH 07/33] param defaults --- src/Psalm/Internal/Codebase/Analyzer.php | 2 +- src/Psalm/Internal/LanguageServer/LanguageServer.php | 2 +- src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php | 2 +- src/Psalm/Issue/CodeIssue.php | 2 +- src/Psalm/Report.php | 2 +- src/Psalm/Storage/FunctionLikeStorage.php | 2 +- src/Psalm/Type/Atomic/TEnumCase.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 37d3c29403a..ccd0bbfb09c 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -345,7 +345,7 @@ function (int $_, string $file_path) use ($project_analyzer, $filetype_analyzers $this->progress->debug('Analyzing ' . $file_analyzer->getFilePath() . "\n"); - $file_analyzer->analyze(null); + $file_analyzer->analyze(); $file_analyzer->context = null; $file_analyzer->clearSourceBeforeDestruction(); unset($file_analyzer); diff --git a/src/Psalm/Internal/LanguageServer/LanguageServer.php b/src/Psalm/Internal/LanguageServer/LanguageServer.php index 90f6c77bf1a..24703864af1 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageServer.php +++ b/src/Psalm/Internal/LanguageServer/LanguageServer.php @@ -220,7 +220,7 @@ function () { $this->verboseLog("Initializing: Registering stub files..."); $this->clientStatus('initializing', 'registering stub files'); - $codebase->config->visitStubFiles($codebase, null); + $codebase->config->visitStubFiles($codebase); if ($this->textDocument === null) { $this->textDocument = new TextDocument( diff --git a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php index 04d41daa332..e2cfdc7b90e 100644 --- a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php +++ b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php @@ -68,7 +68,7 @@ public function enterNode(Node $node): ?int $this->nameContext->startNamespace($node->name); } elseif ($node instanceof Stmt\Use_) { foreach ($node->uses as $use) { - $this->addAlias($use, $node->type, null); + $this->addAlias($use, $node->type); } } elseif ($node instanceof Stmt\GroupUse) { foreach ($node->uses as $use) { diff --git a/src/Psalm/Issue/CodeIssue.php b/src/Psalm/Issue/CodeIssue.php index 3d64cfc4d56..2f2860e84df 100644 --- a/src/Psalm/Issue/CodeIssue.php +++ b/src/Psalm/Issue/CodeIssue.php @@ -87,7 +87,7 @@ public function getMessage(): string return $this->message; } - public function toIssueData(string $severity = Config::REPORT_ERROR): \Psalm\Internal\Analyzer\IssueData + public function toIssueData(string $severity): \Psalm\Internal\Analyzer\IssueData { $location = $this->code_location; $selection_bounds = $location->getSelectionBounds(); diff --git a/src/Psalm/Report.php b/src/Psalm/Report.php index 68cbc331b92..a57b2d30476 100644 --- a/src/Psalm/Report.php +++ b/src/Psalm/Report.php @@ -105,7 +105,7 @@ function ($issue_data) : bool { protected function xmlEncode(string $data): string { - return htmlspecialchars($data, ENT_XML1 | ENT_QUOTES, 'UTF-8'); + return htmlspecialchars($data, ENT_XML1 | ENT_QUOTES); } abstract public function create(): string; diff --git a/src/Psalm/Storage/FunctionLikeStorage.php b/src/Psalm/Storage/FunctionLikeStorage.php index 5a1fe6abfd4..fdef5d4eaaa 100644 --- a/src/Psalm/Storage/FunctionLikeStorage.php +++ b/src/Psalm/Storage/FunctionLikeStorage.php @@ -242,7 +242,7 @@ public function __toString(): string return $this->getSignature(false); } - public function getSignature(bool $allow_newlines = false): string + public function getSignature(bool $allow_newlines): string { $newlines = $allow_newlines && !empty($this->params); diff --git a/src/Psalm/Type/Atomic/TEnumCase.php b/src/Psalm/Type/Atomic/TEnumCase.php index 9e3815c558c..0c0f99a5a23 100644 --- a/src/Psalm/Type/Atomic/TEnumCase.php +++ b/src/Psalm/Type/Atomic/TEnumCase.php @@ -13,7 +13,7 @@ class TEnumCase extends TNamedObject public function __construct(string $fq_enum_name, string $case_name) { - parent::__construct($fq_enum_name, false); + parent::__construct($fq_enum_name); $this->case_name = $case_name; } From c45e9bfc5fb9164ec72da11e370c6981c0be8986 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 21:10:02 +0200 Subject: [PATCH 08/33] useless switch --- src/Psalm/Type/Reconciler.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index cfec9f321fd..0f9334af607 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -102,10 +102,8 @@ public static function reconcileKeyedTypes( foreach ($new_type_parts as $new_type_part_parts) { foreach ($new_type_part_parts as $new_type_part_part) { - switch ($new_type_part_part[0]) { - case '!': - $has_negation = true; - break; + if ($new_type_part_part[0] === '!') { + $has_negation = true; } $has_isset = $has_isset From 5b684309fdaf95263841aaa8fd933e3cca1c9e06 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 21:49:00 +0200 Subject: [PATCH 09/33] unnecessary ternary --- src/Psalm/Internal/Analyzer/ClassAnalyzer.php | 6 +++--- .../Analyzer/Statements/Block/SwitchCaseAnalyzer.php | 2 +- .../Analyzer/Statements/Expression/AssignmentAnalyzer.php | 3 +-- .../Statements/Expression/Fetch/ArrayFetchAnalyzer.php | 3 +-- .../Analyzer/Statements/Expression/IncludeAnalyzer.php | 2 +- src/Psalm/Internal/Cli/LanguageServer.php | 2 +- src/Psalm/Internal/CliUtils.php | 2 +- src/Psalm/Internal/Codebase/ConstantTypeResolver.php | 4 ++-- .../Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php | 2 +- .../Internal/PhpVisitor/Reflector/ExpressionScanner.php | 2 +- .../PhpVisitor/Reflector/FunctionLikeNodeScanner.php | 2 +- 11 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index 5cd72ec1fe6..3060b52c5ec 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -368,7 +368,7 @@ public function analyze( $this->fq_class_name . ', defined abstract in ' . $declaring_class_name, new CodeLocation( $this, - $class->name ? $class->name : $class, + $class->name ?? $class, $class_context->include_location, true ) @@ -984,7 +984,7 @@ private function checkPropertyInitialization( return; } - $fq_class_name = $class_context->self ? $class_context->self : $this->fq_class_name; + $fq_class_name = $class_context->self ?: $this->fq_class_name; $fq_class_name_lc = strtolower($fq_class_name); $included_file_path = $this->getFilePath(); @@ -2276,7 +2276,7 @@ private function checkImplementedInterfaces( $code_location = new CodeLocation( $this, - $class->name ? $class->name : $class, + $class->name ?? $class, $class_context->include_location, true ); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index bbedadc6c62..6b3f391c00e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -402,7 +402,7 @@ public static function analyze( $case_context->inside_loop, new CodeLocation( $statements_analyzer->getSource(), - $case->cond ? $case->cond : $case, + $case->cond ?? $case, $context->include_location ) ); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 02a0c287f4d..8296219dccf 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -232,8 +232,7 @@ public static function analyze( if ($comment_type && $comment_type_location) { $temp_assign_value_type = $assign_value_type - ? $assign_value_type - : ($assign_value ? $statements_analyzer->node_data->getType($assign_value) : null); + ?? ($assign_value ? $statements_analyzer->node_data->getType($assign_value) : null); if ($codebase->find_unused_variables && $temp_assign_value_type diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php index 75b07f42977..cb1f0add720 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php @@ -1833,8 +1833,7 @@ private static function handleArrayAccessOnNamedObject( [ new VirtualArg( $stmt->dim - ? $stmt->dim - : new VirtualConstFetch( + ?? new VirtualConstFetch( new VirtualName('null'), $stmt->var->getAttributes() ) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php index 36a4fbb6ef0..a608ab4c7f0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php @@ -84,7 +84,7 @@ public static function analyze( // attempts to resolve using get_include_path dirs $include_path = self::resolveIncludePath($path_to_file, dirname($statements_analyzer->getFilePath())); - $path_to_file = $include_path ? $include_path : $path_to_file; + $path_to_file = $include_path ?: $path_to_file; if (DIRECTORY_SEPARATOR === '/') { $is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR; diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index d6afd30fcef..691dd6f837f 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -309,6 +309,6 @@ function () use ($current_dir, $options, $vendor_dir): ?\Composer\Autoload\Class $project_analyzer->language_server_verbose = true; } - $project_analyzer->server($options['tcp'] ?? null, isset($options['tcp-server']) ? true : false); + $project_analyzer->server($options['tcp'] ?? null, isset($options['tcp-server'])); } } diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 015f6a34ad3..46441c1754e 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -231,7 +231,7 @@ public static function getPathsToCheck($f_paths): ?array if ($f_paths) { $input_paths = is_array($f_paths) ? $f_paths : [$f_paths]; } else { - $input_paths = $argv ? $argv : null; + $input_paths = $argv ?: null; } if ($input_paths) { diff --git a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php index 99f4345f717..a32fed6f9dc 100644 --- a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php +++ b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php @@ -134,12 +134,12 @@ public static function resolve( || $cond instanceof Type\Atomic\TLiteralString ) { if ($cond->value) { - return $if ? $if : $cond; + return $if ?? $cond; } } elseif ($cond instanceof Type\Atomic\TFalse || $cond instanceof Type\Atomic\TNull) { return $else; } elseif ($cond instanceof Type\Atomic\TTrue) { - return $if ? $if : $cond; + return $if ?? $cond; } } diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index 4d257f5a143..9ab240259a2 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -1403,7 +1403,7 @@ private function visitPropertyDeclaration( $property_storage->type_location = $signature_type_location; $property_storage->location = new CodeLocation($this->file_scanner, $property->name); $property_storage->stmt_location = new CodeLocation($this->file_scanner, $stmt); - $property_storage->has_default = $property->default ? true : false; + $property_storage->has_default = (bool)$property->default; $property_storage->deprecated = $var_comment ? $var_comment->deprecated : false; $property_storage->suppressed_issues = $var_comment ? $var_comment->suppressed_issues : []; $property_storage->internal = $var_comment ? $var_comment->psalm_internal ?? '' : ''; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php index 34b09d9054f..a02a5cb83a8 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php @@ -281,7 +281,7 @@ public static function visitInclude( // attempts to resolve using get_include_path dirs $include_path = IncludeAnalyzer::resolveIncludePath($path_to_file, dirname($file_storage->file_path)); - $path_to_file = $include_path ? $include_path : $path_to_file; + $path_to_file = $include_path ?: $path_to_file; if (DIRECTORY_SEPARATOR === '/') { $is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index 83157e1b3d7..d0117bfe0e0 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -585,7 +585,7 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal $property_storage->type_location = $param_storage->type_location; $property_storage->location = $param_storage->location; $property_storage->stmt_location = new CodeLocation($this->file_scanner, $param); - $property_storage->has_default = $param->default ? true : false; + $property_storage->has_default = (bool)$param->default; $param_storage->promoted_property = true; $property_storage->is_promoted = true; From 5777d02fedc621215b994499f1b9aee9ad437e42 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 21:53:43 +0200 Subject: [PATCH 10/33] missing types --- .../Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php b/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php index 0a675617b79..f9618f0ffa4 100644 --- a/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php +++ b/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php @@ -9,8 +9,11 @@ */ class UnresolvedTernary extends UnresolvedConstantComponent { + /** @var UnresolvedConstantComponent */ public $cond; + /** @var UnresolvedConstantComponent|null */ public $if; + /** @var UnresolvedConstantComponent */ public $else; public function __construct( From be8406294cc309c66021a0c439928b7d48b5dc9d Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 21:58:05 +0200 Subject: [PATCH 11/33] unnecessary return --- .../Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index de730ff64bc..7d6cf6db4c8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -1112,8 +1112,6 @@ private static function handleNonExistentProperty( $has_magic_getter, $var_id ); - - return; } private static function getClassPropertyType( From a5aa824258a44d33e57b913befa80ca260076c04 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:01:36 +0200 Subject: [PATCH 12/33] unnecessary local variable --- src/Psalm/Config/Creator.php | 4 +--- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 4 +--- .../Call/Method/ExistingAtomicMethodCallAnalyzer.php | 4 +--- src/Psalm/Internal/Provider/FileReferenceCacheProvider.php | 5 +---- src/Psalm/Report/PylintReport.php | 4 +--- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/Psalm/Config/Creator.php b/src/Psalm/Config/Creator.php index 6ddf8a7a285..e54294888f7 100644 --- a/src/Psalm/Config/Creator.php +++ b/src/Psalm/Config/Creator.php @@ -76,13 +76,11 @@ public static function getContents( ); } - $template = str_replace( + return str_replace( 'errorLevel="1"', 'errorLevel="' . $level . '"', $template ); - - return $template; } public static function createBareConfig( diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 8dcb978bdfc..1b627792727 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1334,13 +1334,11 @@ public function getFileAnalyzerForClassLike(string $fq_class_name): FileAnalyzer $file_path = $this->codebase->scanner->getClassLikeFilePath($fq_class_name_lc); - $file_analyzer = new FileAnalyzer( + return new FileAnalyzer( $this, $file_path, $this->config->shortenFileName($file_path) ); - - return $file_analyzer; } public function getMethodMutations( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php index e92174acb79..e1d7909325e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php @@ -103,9 +103,7 @@ public static function analyze( $context ); - $function_return = $statements_analyzer->node_data->getType($fake_function_call) ?: Type::getMixed(); - - return $function_return; + return $statements_analyzer->node_data->getType($fake_function_call) ?: Type::getMixed(); } $source = $statements_analyzer->getSource(); diff --git a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php index 34aff48ae39..02b7daa9fb3 100644 --- a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php @@ -818,10 +818,7 @@ public function getConfigHashCache() if ($cache_directory && file_exists($config_hash_cache_location) ) { - /** @var string */ - $file_maps_cache = file_get_contents($config_hash_cache_location); - - return $file_maps_cache; + return file_get_contents($config_hash_cache_location); } return false; diff --git a/src/Psalm/Report/PylintReport.php b/src/Psalm/Report/PylintReport.php index 1e1041dd548..d96354c6e32 100644 --- a/src/Psalm/Report/PylintReport.php +++ b/src/Psalm/Report/PylintReport.php @@ -36,14 +36,12 @@ private function format(\Psalm\Internal\Analyzer\IssueData $issue_data): string // but it's still useful for users. // E.g. jenkins can't parse %s:%d:%d. $message = sprintf('%s (column %d)', $message, $issue_data->column_from); - $issue_string = sprintf( + return sprintf( '%s:%d: [%s] %s', $issue_data->file_name, $issue_data->line_from, $code, $message ); - - return $issue_string; } } From 6dd1e192545d25d3fc4531dd508fcaad94e8eb11 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:02:36 +0200 Subject: [PATCH 13/33] unnecessary ref --- src/Psalm/Internal/Type/AssertionReconciler.php | 2 +- src/Psalm/Internal/Type/TypeExpander.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 9daff509ce7..1e92f79270d 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -1297,7 +1297,7 @@ private static function handleIsA( Codebase $codebase, Union $existing_var_type, string &$assertion, - array &$template_type_map, + array $template_type_map, ?CodeLocation $code_location, ?string $key, array $suppressed_issues, diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index b61735e0558..e7123c461e5 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -664,7 +664,7 @@ private static function expandConditional( bool $evaluate_class_constants = true, bool $evaluate_conditional_types = false, bool $final = false, - bool &$expand_generic = false, + bool $expand_generic = false, bool $expand_templates = false ) { $new_as_type = self::expandUnion( From dae29c8cee412d5d0e434f21380d2db22d279433 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:04:25 +0200 Subject: [PATCH 14/33] missing visibility --- .../Internal/ExecutionEnvironment/SystemCommandExecutor.php | 2 +- src/Psalm/Type/Atomic/TIntRange.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php b/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php index a78e3078d73..89d0e3e02d3 100644 --- a/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php +++ b/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php @@ -24,7 +24,7 @@ public function execute(string $command) : array { if (!\function_exists('exec')) { throw new \RuntimeException(sprintf('exec does not exist, failed to execute command: %s', $command)); - }; + } exec($command, $result, $returnValue); diff --git a/src/Psalm/Type/Atomic/TIntRange.php b/src/Psalm/Type/Atomic/TIntRange.php index c8e9cd35d18..002a09925b3 100644 --- a/src/Psalm/Type/Atomic/TIntRange.php +++ b/src/Psalm/Type/Atomic/TIntRange.php @@ -9,8 +9,8 @@ */ class TIntRange extends TInt { - const BOUND_MIN = 'min'; - const BOUND_MAX = 'max'; + public const BOUND_MIN = 'min'; + public const BOUND_MAX = 'max'; /** * @var int|null From ae1afd90c64d54a1887305e493130545be6b19a3 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:06:24 +0200 Subject: [PATCH 15/33] coalesce operator --- src/Psalm/Codebase.php | 2 +- src/Psalm/Context.php | 2 +- .../Analyzer/Statements/Block/IfElse/IfAnalyzer.php | 2 +- .../Internal/Analyzer/Statements/Block/IfElseAnalyzer.php | 4 +--- .../Analyzer/Statements/Expression/AssertionFinder.php | 2 +- .../Expression/Call/ArrayFunctionArgumentsAnalyzer.php | 2 +- .../Expression/Call/NamedFunctionCallHandler.php | 6 +++--- src/Psalm/Internal/Analyzer/StatementsAnalyzer.php | 4 ++-- src/Psalm/Internal/Cli/Psalm.php | 2 +- src/Psalm/Internal/Cli/Psalter.php | 2 +- .../PhpVisitor/Reflector/ClassLikeDocblockParser.php | 2 +- src/Psalm/Internal/Provider/FileReferenceProvider.php | 8 ++++---- .../ReturnTypeProvider/ArrayFilterReturnTypeProvider.php | 2 +- .../ArrayPointerAdjustmentReturnTypeProvider.php | 2 +- .../ReturnTypeProvider/ArrayPopReturnTypeProvider.php | 2 +- .../ReturnTypeProvider/ArrayRandReturnTypeProvider.php | 4 ++-- .../ReturnTypeProvider/ArraySliceReturnTypeProvider.php | 2 +- .../ReturnTypeProvider/ArrayValuesReturnTypeProvider.php | 2 +- src/Psalm/Internal/Type/TypeCombiner.php | 4 +--- 19 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 63ba4333048..867d0cfaf25 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -614,7 +614,7 @@ public function addGlobalConstantType(string $const_id, Type\Union $type): void public function getStubbedConstantType(string $const_id): ?Type\Union { - return isset(self::$stubbed_constants[$const_id]) ? self::$stubbed_constants[$const_id] : null; + return self::$stubbed_constants[$const_id] ?? null; } /** diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 97c5564b33b..389b92ff3b3 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -418,7 +418,7 @@ public function update( ? $end_context->vars_in_scope[$var_id] : null; - $existing_type = isset($this->vars_in_scope[$var_id]) ? $this->vars_in_scope[$var_id] : null; + $existing_type = $this->vars_in_scope[$var_id] ?? null; if (!$existing_type) { if ($new_type) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php index 24cf46aac88..ac8e7e55d25 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php @@ -139,7 +139,7 @@ public static function analyze( $if_scope->reasonable_clauses = Context::filterClauses( $var_id, $if_scope->reasonable_clauses, - isset($if_context->vars_in_scope[$var_id]) ? $if_context->vars_in_scope[$var_id] : null, + $if_context->vars_in_scope[$var_id] ?? null, $statements_analyzer ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php index 93241c26772..be834a182e1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php @@ -449,9 +449,7 @@ function (array $carry, Clause $clause): array { $if_scope->reasonable_clauses = Context::filterClauses( $var_id, $if_scope->reasonable_clauses, - isset($context->vars_in_scope[$var_id]) - ? $context->vars_in_scope[$var_id] - : null, + $context->vars_in_scope[$var_id] ?? null, $statements_analyzer ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 61ab1f7b988..86ab810ca94 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -3418,7 +3418,7 @@ private static function getIsaAssertions( if ($first_var_name) { $first_arg = $expr->args[0]->value; $second_arg = $expr->args[1]->value; - $third_arg = isset($expr->args[2]->value) ? $expr->args[2]->value : null; + $third_arg = $expr->args[2]->value ?? null; if ($third_arg instanceof PhpParser\Node\Expr\ConstFetch) { if (!in_array(strtolower($third_arg->name->parts[0]), ['true', 'false'])) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php index 70aa20b5f68..0239bc9b2ac 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php @@ -88,7 +88,7 @@ public static function checkArgumentsMatch( $array_arg_types[] = $array_arg_type; } - $closure_arg = isset($args[$closure_index]) ? $args[$closure_index] : null; + $closure_arg = $args[$closure_index] ?? null; $closure_arg_type = null; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php index af3fd3be909..2c687821c54 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php @@ -60,10 +60,10 @@ public static function handle( return; } - $first_arg = isset($stmt->args[0]) ? $stmt->args[0] : null; + $first_arg = $stmt->args[0] ?? null; if ($function_id === 'method_exists') { - $second_arg = isset($stmt->args[1]) ? $stmt->args[1] : null; + $second_arg = $stmt->args[1] ?? null; if ($first_arg && $first_arg->value instanceof PhpParser\Node\Expr\Variable @@ -442,7 +442,7 @@ private static function handleDependentTypeFunction( string $function_id, Context $context ) : void { - $first_arg = isset($stmt->args[0]) ? $stmt->args[0] : null; + $first_arg = $stmt->args[0] ?? null; if ($first_arg) { $var = $first_arg->value; diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 82e0e91f059..0a0f874b4a1 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -911,12 +911,12 @@ public function getParentNodesForPossiblyUndefinedVariable(string $undefined_var */ public function getFirstAppearance(string $var_id): ?CodeLocation { - return isset($this->all_vars[$var_id]) ? $this->all_vars[$var_id] : null; + return $this->all_vars[$var_id] ?? null; } public function getBranchPoint(string $var_id): ?int { - return isset($this->var_branch_points[$var_id]) ? $this->var_branch_points[$var_id] : null; + return $this->var_branch_points[$var_id] ?? null; } public function addVariableInitialization(string $var_id, int $branch_point): void diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index b60ba439065..e1a1224dfca 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -251,7 +251,7 @@ function () use ($current_dir, $options, $vendor_dir): ?\Composer\Autoload\Class } } - $paths_to_check = CliUtils::getPathsToCheck(isset($options['f']) ? $options['f'] : null); + $paths_to_check = CliUtils::getPathsToCheck($options['f'] ?? null); if ($config->resolve_from_config_file) { $current_dir = $config->base_dir; diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index c386fd64ff0..92571bad6b0 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -201,7 +201,7 @@ function () use ($current_dir, $options, $vendor_dir): ?\Composer\Autoload\Class // If Xdebug is enabled, restart without it (new \Composer\XdebugHandler\XdebugHandler('PSALTER'))->check(); - $paths_to_check = CliUtils::getPathsToCheck(isset($options['f']) ? $options['f'] : null); + $paths_to_check = CliUtils::getPathsToCheck($options['f'] ?? null); $path_to_config = CliUtils::getPathToConfig($options); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php index 7702e603942..8c62963a24b 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php @@ -489,7 +489,7 @@ protected static function addMagicPropertyToInfo( array $specials, string $property_tag ) : void { - $magic_property_comments = isset($specials[$property_tag]) ? $specials[$property_tag] : []; + $magic_property_comments = $specials[$property_tag] ?? []; foreach ($magic_property_comments as $offset => $property) { $line_parts = CommentAnalyzer::splitDocLine($property); diff --git a/src/Psalm/Internal/Provider/FileReferenceProvider.php b/src/Psalm/Internal/Provider/FileReferenceProvider.php index 887e6ff32f0..42b033b9b48 100644 --- a/src/Psalm/Internal/Provider/FileReferenceProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceProvider.php @@ -447,7 +447,7 @@ public function removeDeletedFilesFromReferences(): void */ public function getFilesReferencingFile(string $file): array { - return isset(self::$file_references[$file]['a']) ? self::$file_references[$file]['a'] : []; + return self::$file_references[$file]['a'] ?? []; } /** @@ -455,7 +455,7 @@ public function getFilesReferencingFile(string $file): array */ public function getFilesInheritingFromFile(string $file): array { - return isset(self::$file_references[$file]['i']) ? self::$file_references[$file]['i'] : []; + return self::$file_references[$file]['i'] ?? []; } /** @@ -691,14 +691,14 @@ public function updateReferenceCache(Codebase $codebase, array $visited_files): foreach ($visited_files as $file => $_) { $all_file_references = array_unique( array_merge( - isset(self::$file_references[$file]['a']) ? self::$file_references[$file]['a'] : [], + self::$file_references[$file]['a'] ?? [], $this->calculateFilesReferencingFile($codebase, $file) ) ); $inheritance_references = array_unique( array_merge( - isset(self::$file_references[$file]['i']) ? self::$file_references[$file]['i'] : [], + self::$file_references[$file]['i'] ?? [], $this->calculateFilesInheritingFile($codebase, $file) ) ); diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php index 6c95075175e..c87858f12bd 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php @@ -38,7 +38,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return Type::getMixed(); } - $array_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $array_arg = $call_args[0]->value ?? null; $first_arg_array = $array_arg && ($first_arg_type = $statements_source->node_data->getType($array_arg)) diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php index e4794676f8e..32d44bd3c46 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php @@ -24,7 +24,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; if (!$first_arg) { return Type::getMixed(); diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php index 8b4aa693a9c..33b9321d5b7 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php @@ -23,7 +23,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; $first_arg_array = $first_arg && ($first_arg_type = $statements_source->node_data->getType($first_arg)) diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php index 8f22be30341..8e61ae121c7 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php @@ -23,8 +23,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; - $second_arg = isset($call_args[1]->value) ? $call_args[1]->value : null; + $first_arg = $call_args[0]->value ?? null; + $second_arg = $call_args[1]->value ?? null; $first_arg_array = $first_arg && ($first_arg_type = $statements_source->node_data->getType($first_arg)) diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php index cca2571b849..5b8c902768c 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php @@ -23,7 +23,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; if (!$first_arg) { return Type::getArray(); diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php index bbea643aca4..a6a16a9fedb 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php @@ -22,7 +22,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; if (!$first_arg) { return Type::getArray(); diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 320ebc0f379..8c86dd9c7c2 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -684,9 +684,7 @@ private static function scrapeTypeProperties( $has_defined_keys = false; foreach ($type->properties as $candidate_property_name => $candidate_property_type) { - $value_type = isset($combination->objectlike_entries[$candidate_property_name]) - ? $combination->objectlike_entries[$candidate_property_name] - : null; + $value_type = $combination->objectlike_entries[$candidate_property_name] ?? null; if (!$value_type) { $combination->objectlike_entries[$candidate_property_name] = clone $candidate_property_type; From a85cba397327a649d00838e114be732011c7e0c4 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:19:42 +0200 Subject: [PATCH 16/33] dead code --- .../Internal/Analyzer/ClassLikeAnalyzer.php | 23 ++++++++----------- .../Internal/PhpVisitor/ReflectorVisitor.php | 7 +----- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php index f1b66b95e4c..825a9f4b7b7 100644 --- a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php @@ -580,22 +580,17 @@ public static function checkPropertyVisibility( return $emit_issues ? null : true; case self::VISIBILITY_PRIVATE: - if (!$context->self || $appearing_property_class !== $context->self) { - if ($emit_issues && IssueBuffer::accepts( - new InaccessibleProperty( - 'Cannot access private property ' . $property_id . ' from context ' . $context->self, - $code_location - ), - $suppressed_issues - )) { - // fall through - } - - return null; + if ($emit_issues && IssueBuffer::accepts( + new InaccessibleProperty( + 'Cannot access private property ' . $property_id . ' from context ' . $context->self, + $code_location + ), + $suppressed_issues + )) { + // fall through } - return $emit_issues ? null : true; - + return null; case self::VISIBILITY_PROTECTED: if (!$context->self) { if ($emit_issues && IssueBuffer::accepts( diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 3da990b3670..75a3f994d2a 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -126,17 +126,12 @@ public function enterNode(PhpParser\Node $node): ?int { foreach ($node->getComments() as $comment) { if ($comment instanceof PhpParser\Comment\Doc && !$node instanceof PhpParser\Node\Stmt\ClassLike) { - $self_fqcln = $node instanceof PhpParser\Node\Stmt\ClassLike - && $node->name !== null - ? ($this->aliases->namespace ? $this->aliases->namespace . '\\' : '') . $node->name->name - : null; - try { $type_aliases = Reflector\ClassLikeNodeScanner::getTypeAliasesFromComment( $comment, $this->aliases, $this->type_aliases, - $self_fqcln + null ); foreach ($type_aliases as $type_alias) { From 998f91aa65bb687b7f31888fb92fc4424c5d9041 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:23:09 +0200 Subject: [PATCH 17/33] variable with single value --- src/Psalm/Internal/Type/AssertionReconciler.php | 2 +- src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php | 6 +++--- src/Psalm/Type/Atomic/TClassStringMap.php | 4 ++-- src/Psalm/Type/Atomic/TIntMask.php | 2 +- src/Psalm/Type/Atomic/TKeyedArray.php | 2 +- src/Psalm/Type/Atomic/TList.php | 4 ++-- src/Psalm/Type/Atomic/TTemplateParam.php | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 1e92f79270d..2773c54c9cf 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -1075,7 +1075,7 @@ private static function handleLiteralEquality( $existing_var_atomic_type->as = self::handleLiteralEquality( $assertion, $bracket_pos, - $is_loose_equality, + false, $existing_var_atomic_type->as, $old_var_type_string, $var_id, diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index b070730174a..799ef0bad55 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -179,7 +179,7 @@ private static function handleAtomicStandin( $template_result, $codebase, $statements_analyzer, - $replace, + true, $add_lower_bound, $bound_equality_classlike, $depth, @@ -599,7 +599,7 @@ private static function handleTemplateParamStandin( $input_arg_offset, $calling_class, $calling_function, - $replace, + true, $add_lower_bound, $bound_equality_classlike, $depth + 1 @@ -685,7 +685,7 @@ private static function handleTemplateParamStandin( $input_arg_offset, $calling_class, $calling_function, - $replace, + true, $add_lower_bound, $bound_equality_classlike, $depth + 1 diff --git a/src/Psalm/Type/Atomic/TClassStringMap.php b/src/Psalm/Type/Atomic/TClassStringMap.php index acef988c7d3..a9b060d9f50 100644 --- a/src/Psalm/Type/Atomic/TClassStringMap.php +++ b/src/Psalm/Type/Atomic/TClassStringMap.php @@ -92,7 +92,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } @@ -106,7 +106,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + false ) . '>'; } diff --git a/src/Psalm/Type/Atomic/TIntMask.php b/src/Psalm/Type/Atomic/TIntMask.php index c7db8aa42dd..95a08d4447a 100644 --- a/src/Psalm/Type/Atomic/TIntMask.php +++ b/src/Psalm/Type/Atomic/TIntMask.php @@ -70,7 +70,7 @@ public function toNamespacedString( $s = ''; foreach ($this->values as $value) { - $s .= $value->toNamespacedString($namespace, $aliased_classes, $this_class, $use_phpdoc_format) . ', '; + $s .= $value->toNamespacedString($namespace, $aliased_classes, $this_class, false) . ', '; } return 'int-mask<' . substr($s, 0, -2) . '>'; diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index 1ec5c0ff3b8..dd5cb6b2545 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -147,7 +147,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } diff --git a/src/Psalm/Type/Atomic/TList.php b/src/Psalm/Type/Atomic/TList.php index 50a319aa8c8..05781ad092c 100644 --- a/src/Psalm/Type/Atomic/TList.php +++ b/src/Psalm/Type/Atomic/TList.php @@ -68,7 +68,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } @@ -79,7 +79,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + false ) . '>'; } diff --git a/src/Psalm/Type/Atomic/TTemplateParam.php b/src/Psalm/Type/Atomic/TTemplateParam.php index 1ef9d2eec03..b9e5ebc2117 100644 --- a/src/Psalm/Type/Atomic/TTemplateParam.php +++ b/src/Psalm/Type/Atomic/TTemplateParam.php @@ -100,7 +100,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } @@ -108,7 +108,7 @@ public function toNamespacedString( $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + false ); return $this->param_name . $intersection_types; From c11b32d41412a99817dde6ac15a8a2829d245109 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:25:15 +0200 Subject: [PATCH 18/33] redundant variable check --- .../Statements/Block/ForeachAnalyzer.php | 2 +- .../Analyzer/Statements/BreakAnalyzer.php | 5 +---- .../Analyzer/Statements/ContinueAnalyzer.php | 5 +---- .../Expression/AssignmentAnalyzer.php | 5 ++--- .../Expression/Call/ArgumentsAnalyzer.php | 5 ++--- .../Call/NamedFunctionCallHandler.php | 4 +--- .../Statements/Expression/CastAnalyzer.php | 18 ++++++------------ src/Psalm/Internal/Type/ParseTreeCreator.php | 12 ++++++------ 8 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index 124381ebd61..713de3d8d80 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -250,7 +250,7 @@ public static function analyze( $foreach_context->branch_point ?: (int) $stmt->getAttribute('startFilePos'); } - if ($stmt->keyVar && $stmt->keyVar instanceof PhpParser\Node\Expr\Variable && is_string($stmt->keyVar->name)) { + if ($stmt->keyVar instanceof PhpParser\Node\Expr\Variable && is_string($stmt->keyVar->name)) { $key_type = $key_type ?: Type::getMixed(); AssignmentAnalyzer::analyze( diff --git a/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php index 97c2246fb68..2295dff5ca5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php @@ -21,10 +21,7 @@ public static function analyze( if ($loop_scope) { if ($context->break_types && \end($context->break_types) === 'switch' - && (!$stmt->num - || !$stmt->num instanceof PhpParser\Node\Scalar\LNumber - || $stmt->num->value < 2 - ) + && (!$stmt->num instanceof PhpParser\Node\Scalar\LNumber || $stmt->num->value < 2) ) { $loop_scope->final_actions[] = ScopeAnalyzer::ACTION_LEAVE_SWITCH; } else { diff --git a/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php index 49759c6a4cd..f13daeec0ae 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php @@ -17,10 +17,7 @@ public static function analyze( PhpParser\Node\Stmt\Continue_ $stmt, Context $context ): void { - $count = $stmt->num - && $stmt->num instanceof PhpParser\Node\Scalar\LNumber - ? $stmt->num->value - : 1; + $count = $stmt->num instanceof PhpParser\Node\Scalar\LNumber? $stmt->num->value : 1; $loop_scope = $context->loop_scope; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 8296219dccf..aed3c70c5d9 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -1349,9 +1349,8 @@ private static function analyzeDestructuringAssignment( $can_be_empty = !$assign_value_atomic_type instanceof Type\Atomic\TNonEmptyList; } elseif ($assign_value_atomic_type instanceof Type\Atomic\TKeyedArray) { - if ($assign_var_item->key - && ($assign_var_item->key instanceof PhpParser\Node\Scalar\String_ - || $assign_var_item->key instanceof PhpParser\Node\Scalar\LNumber) + if (($assign_var_item->key instanceof PhpParser\Node\Scalar\String_ + || $assign_var_item->key instanceof PhpParser\Node\Scalar\LNumber) && isset($assign_value_atomic_type->properties[$assign_var_item->key->value]) ) { $new_assign_type = diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 5cfba7e5ea4..998b6882e2c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -70,8 +70,7 @@ public static function analyze( : null; // if this modifies the array type based on further args - if ($method_id - && in_array($method_id, ['array_push', 'array_unshift'], true) + if (in_array($method_id, ['array_push', 'array_unshift'], true) && $function_params && isset($args[0]) && isset($args[1]) @@ -89,7 +88,7 @@ public static function analyze( return null; } - if ($method_id && $method_id === 'array_splice' && $function_params && count($args) > 1) { + if ($method_id === 'array_splice' && $function_params && count($args) > 1) { if (ArrayFunctionArgumentsAnalyzer::handleSplice($statements_analyzer, $args, $context) === false) { return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php index 2c687821c54..a55dd9a3d92 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php @@ -223,9 +223,7 @@ public static function handle( if ($function_id === 'func_get_args') { $source = $statements_analyzer->getSource(); - if ($statements_analyzer->data_flow_graph - && $source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer - ) { + if ($source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) { if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph) { foreach ($source->param_nodes as $param_node) { $statements_analyzer->data_flow_graph->addPath( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index 81c2f902c3a..56e1ea91ee3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -66,8 +66,7 @@ public static function analyze( new Type\Atomic\TLiteralInt(1), ]); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $maybe_type->parent_nodes; } @@ -79,8 +78,7 @@ public static function analyze( if ($as_int) { $type = $valid_int_type ?? Type::getInt(); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; } @@ -106,8 +104,7 @@ public static function analyze( $type = Type::getFloat(); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; } @@ -132,8 +129,7 @@ public static function analyze( $type = Type::getBool(); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; } @@ -183,8 +179,7 @@ public static function analyze( $maybe_type = $statements_analyzer->node_data->getType($stmt->expr); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; } @@ -237,8 +232,7 @@ public static function analyze( $type = Type::getArray(); } - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $stmt_expr_type ? $stmt_expr_type->parent_nodes : []; } diff --git a/src/Psalm/Internal/Type/ParseTreeCreator.php b/src/Psalm/Internal/Type/ParseTreeCreator.php index 4c70e4ff384..eb0e680a710 100644 --- a/src/Psalm/Internal/Type/ParseTreeCreator.php +++ b/src/Psalm/Internal/Type/ParseTreeCreator.php @@ -450,7 +450,7 @@ private function handleColon() : void return; } - if ($current_parent && $current_parent instanceof ParseTree\KeyedArrayPropertyTree) { + if ($current_parent instanceof ParseTree\KeyedArrayPropertyTree) { return; } @@ -462,7 +462,7 @@ private function handleColon() : void $current_parent = $this->current_leaf->parent; } - if ($current_parent && $current_parent instanceof ParseTree\ConditionalTree) { + if ($current_parent instanceof ParseTree\ConditionalTree) { if (count($current_parent->children) > 1) { throw new TypeParseTreeException('Cannot process colon in conditional twice'); } @@ -608,12 +608,12 @@ private function handleBar() : void throw new TypeParseTreeException('Unexpected token |'); } - if ($current_parent && $current_parent instanceof ParseTree\UnionTree) { + if ($current_parent instanceof ParseTree\UnionTree) { $this->current_leaf = $current_parent; return; } - if ($current_parent && $current_parent instanceof ParseTree\IntersectionTree) { + if ($current_parent instanceof ParseTree\IntersectionTree) { $this->current_leaf = $current_parent; $current_parent = $this->current_leaf->parent; } @@ -649,12 +649,12 @@ private function handleAmpersand() : void $current_parent = $this->current_leaf->parent; - if ($current_parent && $current_parent instanceof ParseTree\MethodTree) { + if ($current_parent instanceof ParseTree\MethodTree) { $this->createMethodParam($this->type_tokens[$this->t], $current_parent); return; } - if ($current_parent && $current_parent instanceof ParseTree\IntersectionTree) { + if ($current_parent instanceof ParseTree\IntersectionTree) { $this->current_leaf = $current_parent; return; } From ddf74919f62bc2c9536ac641be8d4a0ca84fe738 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:32:00 +0200 Subject: [PATCH 19/33] if with common parts --- .../PhpVisitor/Reflector/AttributeResolver.php | 9 +++------ .../ArrayReduceReturnTypeProvider.php | 12 ++---------- src/Psalm/Internal/Type/ParseTreeCreator.php | 4 +--- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php b/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php index e297ef9f035..5b7dad78a16 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php @@ -26,16 +26,13 @@ public static function resolve( ) : AttributeStorage { if ($stmt->name instanceof PhpParser\Node\Name\FullyQualified) { $fq_type_string = (string)$stmt->name; - - $codebase->scanner->queueClassLikeForScanning($fq_type_string); - $file_storage->referenced_classlikes[strtolower($fq_type_string)] = $fq_type_string; } else { $fq_type_string = ClassLikeAnalyzer::getFQCLNFromNameObject($stmt->name, $aliases); - - $codebase->scanner->queueClassLikeForScanning($fq_type_string); - $file_storage->referenced_classlikes[strtolower($fq_type_string)] = $fq_type_string; } + $codebase->scanner->queueClassLikeForScanning($fq_type_string); + $file_storage->referenced_classlikes[strtolower($fq_type_string)] = $fq_type_string; + $args = []; foreach ($stmt->args as $arg_node) { diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php index 3b38a8bf6ab..3530237f11a 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php @@ -258,11 +258,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev $method_id, $self_class ) ?: Type::getMixed(); - - $reduce_return_type = Type::combineUnionTypes( - $reduce_return_type, - $return_type - ); } else { if (!$codebase->functions->functionExists( $statements_source, @@ -280,12 +275,9 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev ); $return_type = $function_storage->return_type ?: Type::getMixed(); - - $reduce_return_type = Type::combineUnionTypes( - $reduce_return_type, - $return_type - ); } + + $reduce_return_type = Type::combineUnionTypes($reduce_return_type, $return_type); } } diff --git a/src/Psalm/Internal/Type/ParseTreeCreator.php b/src/Psalm/Internal/Type/ParseTreeCreator.php index eb0e680a710..95b812274de 100644 --- a/src/Psalm/Internal/Type/ParseTreeCreator.php +++ b/src/Psalm/Internal/Type/ParseTreeCreator.php @@ -402,10 +402,8 @@ private function handleEllipsisOrEquals(array $type_token) : void $this->current_leaf->parent = $new_leaf; array_pop($current_parent->children); - $current_parent->children[] = $new_leaf; - } else { - $current_parent->children[] = $new_leaf; } + $current_parent->children[] = $new_leaf; $this->current_leaf = $new_leaf; } From 53e4719c1903a0c612d637567931ef6fab29ea35 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:39:01 +0200 Subject: [PATCH 20/33] boolean cast --- src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 2 +- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 2 +- .../Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php | 2 +- src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php | 2 +- .../Internal/Analyzer/Statements/Expression/CallAnalyzer.php | 2 +- .../Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php | 2 +- src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php | 2 +- src/Psalm/Type/Union.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index c0d39267a13..09be8a4e04a 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -170,7 +170,7 @@ public static function verifyReturnType( $function_always_exits = $control_actions === [ScopeAnalyzer::ACTION_END]; - $function_returns_implicitly = !!array_diff( + $function_returns_implicitly = (bool)array_diff( $control_actions, [ScopeAnalyzer::ACTION_END, ScopeAnalyzer::ACTION_RETURN] ); diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 1b627792727..75210b6fe60 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -660,7 +660,7 @@ public function consolidateAnalyzedData(): void $this->codebase->classlikes->consolidateAnalyzedData( $this->codebase->methods, $this->progress, - !!$this->codebase->find_unused_code + (bool)$this->codebase->find_unused_code ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php index de9a0169021..9ff0bda05ae 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php @@ -159,7 +159,7 @@ function ($c) use ($reconciled_expression_clauses): bool { if (array_filter( $entry_clauses, function ($clause): bool { - return !!$clause->possibilities; + return (bool)$clause->possibilities; } )) { $omit_keys = array_reduce( diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php index be834a182e1..26de808b925 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php @@ -234,7 +234,7 @@ function ($c) use ($reconciled_expression_clauses): bool { if (array_filter( $context->clauses, function ($clause): bool { - return !!$clause->possibilities; + return (bool)$clause->possibilities; } )) { $omit_keys = array_reduce( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index c0412d8b101..b7331d6fbe6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -1027,7 +1027,7 @@ public static function checkTemplateResult( $bounds_with_equality = array_filter( $lower_bounds, function ($lower_bound) { - return !!$lower_bound->equality_bound_classlike; + return (bool)$lower_bound->equality_bound_classlike; } ); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index d0117bfe0e0..f4c8c441a89 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -218,7 +218,7 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal } $existing_params['$' . $param_storage->name] = $i; - $storage->addParam($param_storage, !!$param->type); + $storage->addParam($param_storage, (bool)$param->type); if (!$param_storage->is_optional && !$param_storage->is_variadic) { $required_param_count = $i + 1; diff --git a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php index 622047b4759..12eb39ea71d 100644 --- a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php @@ -381,7 +381,7 @@ public static function canBeContainedBy( } } - return !!$matching_input_keys; + return (bool)$matching_input_keys; } /** diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 00c0ca9e43c..50564eaeca9 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -637,7 +637,7 @@ function ($type): bool { public function hasArrayAccessInterface(Codebase $codebase) : bool { - return !!array_filter( + return (bool)array_filter( $this->types, function ($type) use ($codebase) { return $type->hasArrayAccessInterface($codebase); From a95cb150560db655c00dc073cfd4258995330ae2 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:39:37 +0200 Subject: [PATCH 21/33] no need for parent --- src/Psalm/Type/Atomic/TGenericObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Type/Atomic/TGenericObject.php b/src/Psalm/Type/Atomic/TGenericObject.php index 4d0b8c755d6..f6b387015fd 100644 --- a/src/Psalm/Type/Atomic/TGenericObject.php +++ b/src/Psalm/Type/Atomic/TGenericObject.php @@ -69,7 +69,7 @@ public function toPhpString( int $php_major_version, int $php_minor_version ): ?string { - return parent::toNamespacedString($namespace, $aliased_classes, $this_class, false); + return $this->toNamespacedString($namespace, $aliased_classes, $this_class, false); } public function equals(Atomic $other_type, bool $ensure_source_equality): bool From 18b0c63de2ad82e45d0cf11722c8fde8ca72dc54 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:44:33 +0200 Subject: [PATCH 22/33] shorter operations --- src/Psalm/FileManipulation.php | 2 +- .../Statements/Expression/Fetch/ArrayFetchAnalyzer.php | 2 +- .../Analyzer/Statements/UnusedAssignmentRemover.php | 6 +++--- src/Psalm/IssueBuffer.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Psalm/FileManipulation.php b/src/Psalm/FileManipulation.php index 891f02dacc0..e94489fe5b6 100644 --- a/src/Psalm/FileManipulation.php +++ b/src/Psalm/FileManipulation.php @@ -55,7 +55,7 @@ public function transform(string $existing_contents) : string $indentation = substr($existing_contents, $newline_pos, $this->start - $newline_pos); if (trim($indentation) === '') { - $this->insertion_text = $this->insertion_text . $indentation; + $this->insertion_text .= $indentation; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php index cb1f0add720..d85dc8c717a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php @@ -1956,7 +1956,7 @@ private static function handleArrayAccessOnString( if ($type instanceof TSingleLetter) { $valid_offset_type = Type::getInt(false, 0); } elseif ($type instanceof TLiteralString) { - if (!strlen($type->value)) { + if ($type->value === '') { $valid_offset_type = Type::getEmpty(); } elseif (strlen($type->value) < 10) { $valid_offsets = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php b/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php index 0fa0ca3bb21..5d25d735f07 100644 --- a/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php +++ b/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php @@ -132,7 +132,7 @@ private static function getPartialRemovalBounds( $iter = 1; // Check if second token is just whitespace - if (is_array($token_list[$iter]) && strlen(trim($token_list[$iter][1])) === 0) { + if (is_array($token_list[$iter]) && trim($token_list[$iter][1]) === '') { $offset_count += strlen($token_list[1][1]); $iter++; } @@ -146,7 +146,7 @@ private static function getPartialRemovalBounds( $iter++; // Remove any whitespace following assignment operator token (e.g "=", "+=") - if (is_array($token_list[$iter]) && strlen(trim($token_list[$iter][1])) === 0) { + if (is_array($token_list[$iter]) && trim($token_list[$iter][1]) === '') { $offset_count += strlen($token_list[$iter][1]); $iter++; } @@ -156,7 +156,7 @@ private static function getPartialRemovalBounds( $offset_count += 1; $iter++; // Handle any whitespace after "&" - if (is_array($token_list[$iter]) && strlen(trim($token_list[$iter][1])) === 0) { + if (is_array($token_list[$iter]) && trim($token_list[$iter][1]) === '') { $offset_count += strlen($token_list[$iter][1]); } } diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index e07d60babce..75ce8ed8cd0 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -531,12 +531,12 @@ function (IssueData $d1, IssueData $d2) : int { if ($position !== false) { $issue_data->severity = Config::REPORT_INFO; array_splice($issue_baseline[$file][$type]['s'], $position, 1); - $issue_baseline[$file][$type]['o'] = $issue_baseline[$file][$type]['o'] - 1; + $issue_baseline[$file][$type]['o']--; } } else { $issue_baseline[$file][$type]['s'] = []; $issue_data->severity = Config::REPORT_INFO; - $issue_baseline[$file][$type]['o'] = $issue_baseline[$file][$type]['o'] - 1; + $issue_baseline[$file][$type]['o']--; } } From 46801c4b98cf9274009c8afda235ca25110b8434 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:51:44 +0200 Subject: [PATCH 23/33] clearer string operations --- src/Psalm/Config.php | 2 +- src/Psalm/DocComment.php | 5 +++-- .../Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 2 +- src/Psalm/Internal/Analyzer/MethodComparator.php | 2 +- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 2 +- .../Statements/Block/SwitchCaseAnalyzer.php | 2 +- .../Statements/Expression/AssertionFinder.php | 8 ++++---- .../Statements/Expression/AssignmentAnalyzer.php | 2 +- src/Psalm/Internal/Analyzer/StatementsAnalyzer.php | 3 ++- src/Psalm/Internal/Cli/LanguageServer.php | 2 +- src/Psalm/Internal/Cli/Psalm.php | 4 ++-- src/Psalm/Internal/Cli/Psalter.php | 2 +- src/Psalm/Internal/Cli/Refactor.php | 2 +- src/Psalm/Internal/CliUtils.php | 2 +- src/Psalm/Internal/Codebase/DataFlowGraph.php | 6 +++--- .../Internal/Codebase/InternalCallMapHandler.php | 2 +- .../Reflector/FunctionLikeDocblockParser.php | 4 ++-- .../Reflector/FunctionLikeDocblockScanner.php | 2 +- src/Psalm/Internal/Provider/StatementsProvider.php | 2 +- src/Psalm/Internal/Scanner/DocblockParser.php | 2 +- src/Psalm/Internal/Type/AssertionReconciler.php | 10 +++++----- .../Internal/Type/Comparator/ObjectComparator.php | 14 +++++++------- .../Internal/Type/NegatedAssertionReconciler.php | 6 +++--- .../Internal/Type/SimpleAssertionReconciler.php | 10 +++++----- .../Type/SimpleNegatedAssertionReconciler.php | 4 ++-- .../Internal/Type/TemplateInferredTypeReplacer.php | 2 +- src/Psalm/Internal/Type/TypeParser.php | 2 +- src/Psalm/Internal/TypeVisitor/TypeChecker.php | 2 +- src/Psalm/IssueBuffer.php | 4 ++-- src/Psalm/Progress/Progress.php | 2 +- src/Psalm/Report/SarifReport.php | 2 +- src/Psalm/Type/Atomic.php | 2 +- 32 files changed, 60 insertions(+), 58 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index bd8ad77d24d..0165b2b67f3 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -2115,7 +2115,7 @@ public function getPotentialComposerFilePathForClassLike(string $class): ?string $psr4_prefixes = $this->composer_class_loader->getPrefixesPsr4(); // PSR-4 lookup - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; + $logicalPathPsr4 = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; $candidate_path = null; diff --git a/src/Psalm/DocComment.php b/src/Psalm/DocComment.php index e4b2f53bcff..bb0fb86ea5b 100644 --- a/src/Psalm/DocComment.php +++ b/src/Psalm/DocComment.php @@ -16,6 +16,7 @@ use function str_repeat; use function str_replace; use function strlen; +use function strpos; use function strspn; use function substr; use function trim; @@ -156,7 +157,7 @@ public static function parse(string $docblock, ?int $line_number = null, bool $p $docblock = preg_replace('/^\s*\n/', '', $docblock); foreach ($special as $special_key => $_) { - if (substr($special_key, 0, 6) === 'psalm-') { + if (strpos($special_key, 'psalm-') === 0) { $special_key = substr($special_key, 6); if (!in_array( @@ -186,7 +187,7 @@ public static function parsePreservingLength(\PhpParser\Comment\Doc $docblock) : ); foreach ($parsed_docblock->tags as $special_key => $_) { - if (substr($special_key, 0, 6) === 'psalm-') { + if (strpos($special_key, 'psalm-') === 0) { $special_key = substr($special_key, 6); if (!in_array( diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 09be8a4e04a..c2ff4e629d3 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -109,7 +109,7 @@ public static function verifyReturnType( $is_to_string = $function instanceof ClassMethod && strtolower($function->name->name) === '__tostring'; if ($function instanceof ClassMethod - && substr($function->name->name, 0, 2) === '__' + && strpos($function->name->name, '__') === 0 && !$is_to_string && !$return_type ) { diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index 977f23448f7..af25360559d 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -412,7 +412,7 @@ private static function compareMethodParams( && $implementer_classlike_storage->user_defined && $implementer_param->location && $guide_method_storage->cased_name - && substr($guide_method_storage->cased_name, 0, 2) !== '__' + && strpos($guide_method_storage->cased_name, '__') !== 0 && $config->isInProjectDirs( $implementer_param->location->file_path ) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 75210b6fe60..ad7eb1b4641 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -688,7 +688,7 @@ public function interpretRefactors() : void && $destination_pos === (strlen($destination) - 1) ) { foreach ($this->codebase->classlike_storage_provider->getAll() as $class_storage) { - if (substr($class_storage->name, 0, $source_pos) === substr($source, 0, -1)) { + if (strpos($source, substr($class_storage->name, 0, $source_pos)) === 0) { $this->to_refactor[$class_storage->name] = substr($destination, 0, -1) . substr($class_storage->name, $source_pos); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index 6b3f391c00e..ba4435446a3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -82,7 +82,7 @@ public static function analyze( $fake_switch_condition = false; - if ($switch_var_id && substr($switch_var_id, 0, 15) === '$__tmp_switch__') { + if ($switch_var_id && strpos($switch_var_id, '$__tmp_switch__') === 0) { $switch_condition = new VirtualVariable( substr($switch_var_id, 1), $stmt->cond->getAttributes() diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 86ab810ca94..37aad0f5d60 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -2492,7 +2492,7 @@ private static function getGettypeInequalityAssertions( $if_types[$var_name] = [['!=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['!closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['!=resource']]; } else { $if_types[$var_name] = [['!' . $var_type]]; @@ -2550,7 +2550,7 @@ private static function getGetdebugTypeInequalityAssertions( $if_types[$var_name] = [['!=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['!closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['!=resource']]; } else { $if_types[$var_name] = [['!' . $var_type]]; @@ -3173,7 +3173,7 @@ private static function getGettypeEqualityAssertions( $if_types[$var_name] = [['=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['=resource']]; } else { $if_types[$var_name] = [[$var_type]]; @@ -3231,7 +3231,7 @@ private static function getGetdebugtypeEqualityAssertions( $if_types[$var_name] = [['=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['=resource']]; } else { $if_types[$var_name] = [[$var_type]]; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index aed3c70c5d9..d076a159252 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -360,7 +360,7 @@ public static function analyze( if (!$assign_var instanceof PhpParser\Node\Expr\PropertyFetch && !strpos($root_var_id ?? '', '->') && !$comment_type - && substr($var_id ?? '', 0, 2) !== '$_' + && strpos($var_id ?? '', '$_') !== 0 ) { $origin_locations = []; diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 0a0f874b4a1..80c0bfb9c6f 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -55,6 +55,7 @@ use function preg_split; use function round; use function strlen; +use function strpos; use function strrpos; use function strtolower; use function substr; @@ -755,7 +756,7 @@ public function checkUnreferencedVars(array $stmts, Context $context): void } foreach ($this->unused_var_locations as [$var_id, $original_location]) { - if (substr($var_id, 0, 2) === '$_') { + if (strpos($var_id, '$_') === 0) { continue; } diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index 691dd6f837f..390734278f0 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -85,7 +85,7 @@ public static function run(array $argv): void * @param string $arg */ function ($arg) use ($valid_long_options): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if (!in_array($arg_name, $valid_long_options, true) diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index e1a1224dfca..7e80ad592d5 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -420,7 +420,7 @@ private static function validateCliArguments(array $args): void * @param string $arg */ function ($arg): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if (!in_array($arg_name, self::LONG_OPTIONS) @@ -434,7 +434,7 @@ function ($arg): void { ); exit(1); } - } elseif (substr($arg, 0, 1) === '-' && $arg !== '-' && $arg !== '--') { + } elseif (strpos($arg, '-') === 0 && $arg !== '-' && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 1)); if (!in_array($arg_name, self::SHORT_OPTIONS) diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index 92571bad6b0..40bd193f3d9 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -434,7 +434,7 @@ private static function validateCliArguments($args): void * @param string $arg */ function ($arg): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if ($arg_name === 'alter') { diff --git a/src/Psalm/Internal/Cli/Refactor.php b/src/Psalm/Internal/Cli/Refactor.php index d235c968a72..b63ef6d10e9 100644 --- a/src/Psalm/Internal/Cli/Refactor.php +++ b/src/Psalm/Internal/Cli/Refactor.php @@ -75,7 +75,7 @@ public static function run(array $argv): void * @param string $arg */ function ($arg) use ($valid_long_options): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if ($arg_name === 'refactor') { diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 46441c1754e..821c48ffb72 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -264,7 +264,7 @@ public static function getPathsToCheck($f_paths): ?array continue; } - if (substr($input_path, 0, 2) === '--' && strlen($input_path) > 2) { + if (strpos($input_path, '--') === 0 && strlen($input_path) > 2) { if (substr($input_path, 2) === 'config') { ++$i; } diff --git a/src/Psalm/Internal/Codebase/DataFlowGraph.php b/src/Psalm/Internal/Codebase/DataFlowGraph.php index 5d4f9547a77..d8497bd7b2b 100644 --- a/src/Psalm/Internal/Codebase/DataFlowGraph.php +++ b/src/Psalm/Internal/Codebase/DataFlowGraph.php @@ -65,7 +65,7 @@ protected static function shouldIgnoreFetch( // arraykey-fetch requires a matching arraykey-assignment at the same level // otherwise the tainting is not valid - if (substr($path_type, 0, $el + 7) === $expression_type . '-fetch-' || $path_type === 'arraykey-fetch') { + if (strpos($path_type, $expression_type . '-fetch-') === 0 || $path_type === 'arraykey-fetch') { $fetch_nesting = 0; $previous_path_types = array_reverse($previous_path_types); @@ -79,11 +79,11 @@ protected static function shouldIgnoreFetch( $fetch_nesting--; } - if (substr($previous_path_type, 0, $el + 6) === $expression_type . '-fetch') { + if (strpos($previous_path_type, $expression_type . '-fetch') === 0) { $fetch_nesting++; } - if (substr($previous_path_type, 0, $el + 12) === $expression_type . '-assignment-') { + if (strpos($previous_path_type, $expression_type . '-assignment-') === 0) { if ($fetch_nesting > 0) { $fetch_nesting--; continue; diff --git a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php index 57c187a60b9..e33eaffb077 100644 --- a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php +++ b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php @@ -274,7 +274,7 @@ public static function getCallablesFromCallMap(string $function_id): ?array $optional = true; } - if (substr($arg_name, 0, 3) === '...') { + if (strpos($arg_name, '...') === 0) { $arg_name = substr($arg_name, 3); $variadic = true; } diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php index 7aac2cc420a..7f0aab3eabc 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php @@ -199,7 +199,7 @@ public static function parse(PhpParser\Comment\Doc $comment): FunctionDocblockCo if (count($param_parts) === 2) { $taint_type = $param_parts[1]; - if (substr($taint_type, 0, 5) === 'exec_') { + if (strpos($taint_type, 'exec_') === 0) { $taint_type = substr($taint_type, 5); if ($taint_type === 'tainted') { @@ -375,7 +375,7 @@ public static function parse(PhpParser\Comment\Doc $comment): FunctionDocblockCo } } - if (strpos(strtolower($parsed_docblock->description), '@inheritdoc') !== false + if (stripos($parsed_docblock->description, '@inheritdoc') !== false || isset($parsed_docblock->tags['inheritdoc']) || isset($parsed_docblock->tags['inheritDoc']) ) { diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php index 8c01914be31..5015b2528d1 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php @@ -617,7 +617,7 @@ private static function improveParamsFromDocblock( $param_name = $docblock_param['name']; $docblock_param_variadic = false; - if (substr($param_name, 0, 3) === '...') { + if (strpos($param_name, '...') === 0) { $docblock_param_variadic = true; $param_name = substr($param_name, 3); } diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index 47aed3ef8cc..ef1be0e48bb 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -227,7 +227,7 @@ function ($_): bool { $changed_members = array_map( function (string $key) use ($file_path_hash) : string { - if (substr($key, 0, 4) === 'use:') { + if (strpos($key, 'use:') === 0) { return $key . ':' . $file_path_hash; } diff --git a/src/Psalm/Internal/Scanner/DocblockParser.php b/src/Psalm/Internal/Scanner/DocblockParser.php index 58e6c826870..aa9a11c3012 100644 --- a/src/Psalm/Internal/Scanner/DocblockParser.php +++ b/src/Psalm/Internal/Scanner/DocblockParser.php @@ -31,7 +31,7 @@ public static function parse(string $docblock, int $offsetStart) : ParsedDocbloc // Strip off comments. $docblock = trim($docblock); - if (substr($docblock, 0, 3) === '/**') { + if (strpos($docblock, '/**') === 0) { $docblock = substr($docblock, 3); } diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 2773c54c9cf..2fc30291f6f 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -147,7 +147,7 @@ public static function reconcile( return $simply_reconciled_type; } - if (substr($assertion, 0, 4) === 'isa-') { + if (strpos($assertion, 'isa-') === 0) { $should_return = false; $new_type = self::handleIsA( @@ -164,7 +164,7 @@ public static function reconcile( if ($should_return) { return $new_type; } - } elseif (substr($assertion, 0, 9) === 'getclass-') { + } elseif (strpos($assertion, 'getclass-') === 0) { $assertion = substr($assertion, 9); $new_type = Type::parseString($assertion, null, $template_type_map); } else { @@ -1003,7 +1003,7 @@ private static function handleLiteralEquality( $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if (substr($atomic_key, 0, 6) === 'float(') { + if (strpos($atomic_key, 'float(') === 0) { $atomic_key = 'int(' . substr($atomic_key, 6); } if ($atomic_key !== $assertion) { @@ -1211,7 +1211,7 @@ private static function handleLiteralEquality( $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if (substr($atomic_key, 0, 4) === 'int(') { + if (strpos($atomic_key, 'int(') === 0) { $atomic_key = 'float(' . substr($atomic_key, 4); } if ($atomic_key !== $assertion) { @@ -1307,7 +1307,7 @@ private static function handleIsA( $allow_string_comparison = false; - if (substr($assertion, 0, 7) === 'string-') { + if (strpos($assertion, 'string-') === 0) { $assertion = substr($assertion, 7); $allow_string_comparison = true; } diff --git a/src/Psalm/Internal/Type/Comparator/ObjectComparator.php b/src/Psalm/Internal/Type/Comparator/ObjectComparator.php index 017ef53e0d2..22d451e8aa3 100644 --- a/src/Psalm/Internal/Type/Comparator/ObjectComparator.php +++ b/src/Psalm/Internal/Type/Comparator/ObjectComparator.php @@ -76,11 +76,11 @@ public static function isShallowlyContainedBy( foreach ($intersection_input_types as $intersection_input_type) { if ($intersection_input_type instanceof TTemplateParam - && (\substr($intersection_container_type->defining_class, 0, 3) === 'fn-' - || \substr($intersection_input_type->defining_class, 0, 3) === 'fn-') + && (\strpos($intersection_container_type->defining_class, 'fn-') === 0 + || \strpos($intersection_input_type->defining_class, 'fn-') === 0) ) { - if (\substr($intersection_input_type->defining_class, 0, 3) === 'fn-' - && \substr($intersection_container_type->defining_class, 0, 3) === 'fn-' + if (\strpos($intersection_input_type->defining_class, 'fn-') === 0 + && \strpos($intersection_container_type->defining_class, 'fn-') === 0 && $intersection_input_type->defining_class !== $intersection_container_type->defining_class ) { @@ -191,10 +191,10 @@ public static function isShallowlyContainedBy( if ($intersection_container_type->param_name !== $intersection_input_type->param_name || ($intersection_container_type->defining_class !== $intersection_input_type->defining_class - && \substr($intersection_input_type->defining_class, 0, 3) !== 'fn-' - && \substr($intersection_container_type->defining_class, 0, 3) !== 'fn-') + && \strpos($intersection_input_type->defining_class, 'fn-') !== 0 + && \strpos($intersection_container_type->defining_class, 'fn-') !== 0) ) { - if (\substr($intersection_input_type->defining_class, 0, 3) !== 'fn-') { + if (\strpos($intersection_input_type->defining_class, 'fn-') !== 0) { $input_class_storage = $codebase->classlike_storage_provider->get( $intersection_input_type->defining_class ); diff --git a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php index 8a0d687877c..2c11ee93c57 100644 --- a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php @@ -159,7 +159,7 @@ public static function reconcile( return Type::getEmpty(); } - if (substr($assertion, 0, 9) === 'in-array-') { + if (strpos($assertion, 'in-array-') === 0) { $assertion = substr($assertion, 9); $new_var_type = null; try { @@ -195,7 +195,7 @@ public static function reconcile( return $existing_var_type; } - if (substr($assertion, 0, 14) === 'has-array-key-') { + if (strpos($assertion, 'has-array-key-') === 0) { return $existing_var_type; } } @@ -283,7 +283,7 @@ public static function reconcile( ) { $existing_var_type->removeType('array-key'); $existing_var_type->addType(new TString); - } elseif (substr($assertion, 0, 9) === 'getclass-') { + } elseif (strpos($assertion, 'getclass-') === 0) { $assertion = substr($assertion, 9); } elseif (!$is_equality) { $codebase = $statements_analyzer->getCodebase(); diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index d57453eda3a..d757708d84c 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -87,7 +87,7 @@ public static function reconcile( return $existing_var_type; } - if (substr($assertion, 0, 9) === 'in-array-') { + if (strpos($assertion, 'in-array-') === 0) { return self::reconcileInArray( $codebase, $existing_var_type, @@ -100,7 +100,7 @@ public static function reconcile( ); } - if (substr($assertion, 0, 14) === 'has-array-key-') { + if (strpos($assertion, 'has-array-key-') === 0) { return self::reconcileHasArrayKey( $existing_var_type, substr($assertion, 14) @@ -369,7 +369,7 @@ public static function reconcile( ); } - if (substr($assertion, 0, 13) === 'has-at-least-') { + if (strpos($assertion, 'has-at-least-') === 0) { return self::reconcileNonEmptyCountable( $existing_var_type, $key, @@ -382,7 +382,7 @@ public static function reconcile( ); } - if (substr($assertion, 0, 12) === 'has-exactly-') { + if (strpos($assertion, 'has-exactly-') === 0) { /** @psalm-suppress ArgumentTypeCoercion */ return self::reconcileExactlyCountable( $existing_var_type, @@ -390,7 +390,7 @@ public static function reconcile( ); } - if (substr($assertion, 0, 10) === 'hasmethod-') { + if (strpos($assertion, 'hasmethod-') === 0) { return self::reconcileHasMethod( $codebase, substr($assertion, 10), diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index ab6b41e09f0..a197250cf91 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -217,7 +217,7 @@ public static function reconcile( ); } - if (substr($assertion, 0, 13) === 'has-at-least-') { + if (strpos($assertion, 'has-at-least-') === 0) { return self::reconcileNonEmptyCountable( $existing_var_type, $key, @@ -230,7 +230,7 @@ public static function reconcile( ); } - if (substr($assertion, 0, 12) === 'has-exactly-') { + if (strpos($assertion, 'has-exactly-') === 0) { return $existing_var_type; } diff --git a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php index a1cd6fdff8f..7767681514b 100644 --- a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php @@ -83,7 +83,7 @@ public static function replace( } elseif ($codebase) { foreach ($inferred_lower_bounds as $template_type_map) { foreach ($template_type_map as $template_class => $_) { - if (substr($template_class, 0, 3) === 'fn-') { + if (strpos($template_class, 'fn-') === 0) { continue; } diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 77100f9fa6a..afc35d2601f 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -1183,7 +1183,7 @@ private static function getTypeFromIndexAccessTree( $array_defining_class = array_keys($template_type_map[$array_param_name])[0]; if ($offset_defining_class !== $array_defining_class - && substr($offset_defining_class, 0, 3) !== 'fn-' + && strpos($offset_defining_class, 'fn-') !== 0 ) { throw new TypeParseTreeException('Template params are defined in different locations'); } diff --git a/src/Psalm/Internal/TypeVisitor/TypeChecker.php b/src/Psalm/Internal/TypeVisitor/TypeChecker.php index 3993d8567c8..d402cbd01e7 100644 --- a/src/Psalm/Internal/TypeVisitor/TypeChecker.php +++ b/src/Psalm/Internal/TypeVisitor/TypeChecker.php @@ -355,7 +355,7 @@ public function checkScalarClassConstant(TClassConstant $atomic) : void public function checkTemplateParam(\Psalm\Type\Atomic\TTemplateParam $atomic) : void { if ($this->prevent_template_covariance - && \substr($atomic->defining_class, 0, 3) !== 'fn-' + && \strpos($atomic->defining_class, 'fn-') !== 0 ) { $codebase = $this->source->getCodebase(); diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 75ce8ed8cd0..9b773d48548 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -115,7 +115,7 @@ public static function accepts(CodeIssue $e, array $suppressed_issues = [], bool public static function addUnusedSuppression(string $file_path, int $offset, string $issue_type) : void { - if (\substr($issue_type, 0, 7) === 'Tainted') { + if (\strpos($issue_type, 'Tainted') === 0) { return; } @@ -215,7 +215,7 @@ public static function add(CodeIssue $e, bool $is_fixable = false): bool return false; } - $is_tainted = \substr($issue_type, 0, 7) === 'Tainted'; + $is_tainted = \strpos($issue_type, 'Tainted') === 0; if ($project_analyzer->getCodebase()->taint_flow_graph && !$is_tainted) { return false; diff --git a/src/Psalm/Progress/Progress.php b/src/Psalm/Progress/Progress.php index 7bf84b561d3..06c4efd52d2 100644 --- a/src/Psalm/Progress/Progress.php +++ b/src/Psalm/Progress/Progress.php @@ -54,7 +54,7 @@ public function write(string $message): void protected static function doesTerminalSupportUtf8() : bool { - if (\strtoupper(\substr(PHP_OS, 0, 3)) === 'WIN') { + if (\stripos(PHP_OS, 'WIN') === 0) { if (!\function_exists('sapi_windows_cp_is_utf8') || !\sapi_windows_cp_is_utf8()) { return false; } diff --git a/src/Psalm/Report/SarifReport.php b/src/Psalm/Report/SarifReport.php index 6a1e41378d6..b63e4cb385b 100644 --- a/src/Psalm/Report/SarifReport.php +++ b/src/Psalm/Report/SarifReport.php @@ -45,7 +45,7 @@ public function create(): string ], 'properties' => [ 'tags' => [ - (\substr($issue_data->type, 0, 7) === 'Tainted') ? 'security' : 'maintainability', + (\strpos($issue_data->type, 'Tainted') === 0) ? 'security' : 'maintainability', ], ], 'helpUri' => $issue_data->link, diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index 9b6e7c92d7c..dfc41e3a9f5 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -289,7 +289,7 @@ public static function create( return new TNonEmptyMixed(); } - if (strpos($value, '-') && substr($value, 0, 4) !== 'OCI-') { + if (strpos($value, '-') && strpos($value, 'OCI-') !== 0) { throw new \Psalm\Exception\TypeParseTreeException('Unrecognized type ' . $value); } From f788fec54035e8fd4373157944d77ac7cfcb68df Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:56:52 +0200 Subject: [PATCH 24/33] static::class --- src/Psalm/Issue/CodeIssue.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Psalm/Issue/CodeIssue.php b/src/Psalm/Issue/CodeIssue.php index 2f2860e84df..871b89d4795 100644 --- a/src/Psalm/Issue/CodeIssue.php +++ b/src/Psalm/Issue/CodeIssue.php @@ -2,11 +2,9 @@ namespace Psalm\Issue; use Psalm\CodeLocation; -use Psalm\Config; use function array_pop; use function explode; -use function get_called_class; abstract class CodeIssue { @@ -93,7 +91,7 @@ public function toIssueData(string $severity): \Psalm\Internal\Analyzer\IssueDat $selection_bounds = $location->getSelectionBounds(); $snippet_bounds = $location->getSnippetBounds(); - $fqcn_parts = explode('\\', get_called_class()); + $fqcn_parts = explode('\\', static::class); $issue_type = array_pop($fqcn_parts); return new \Psalm\Internal\Analyzer\IssueData( From 72eab30a3a77664caa153335ecddd60f3b64dc8a Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 22:57:04 +0200 Subject: [PATCH 25/33] coalesce operator --- src/Psalm/Codebase.php | 2 +- src/Psalm/Config.php | 6 +----- src/Psalm/Internal/Analyzer/CanAlias.php | 4 ++-- src/Psalm/Internal/Analyzer/ClassAnalyzer.php | 8 +++----- .../Internal/Analyzer/ClassLikeAnalyzer.php | 2 +- .../Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 14 +++++++------- .../Expression/Call/ArgumentAnalyzer.php | 16 ++++++++-------- .../Expression/Call/ArgumentsAnalyzer.php | 14 +++++++------- .../Call/Method/MethodVisibilityAnalyzer.php | 5 +---- .../Expression/Call/NamedFunctionCallHandler.php | 6 +----- .../Statements/Expression/CallAnalyzer.php | 6 +++--- .../Statements/Expression/CastAnalyzer.php | 10 +++++----- .../Analyzer/Statements/ReturnAnalyzer.php | 2 +- .../Internal/Analyzer/StatementsAnalyzer.php | 2 +- src/Psalm/Internal/Codebase/Analyzer.php | 2 +- src/Psalm/Internal/Codebase/Methods.php | 14 +++----------- .../FileManipulation/FileManipulationBuffer.php | 6 +----- .../PhpVisitor/Reflector/AttributeResolver.php | 6 +----- .../Reflector/ClassLikeNodeScanner.php | 2 +- .../Reflector/FunctionLikeNodeScanner.php | 2 +- .../Internal/PhpVisitor/ReflectorVisitor.php | 4 ++-- src/Psalm/Internal/Provider/FakeFileProvider.php | 12 ++---------- .../Type/Comparator/CallableTypeComparator.php | 2 +- .../Type/Comparator/IntegerRangeComparator.php | 10 +--------- .../Type/TemplateStandinTypeReplacer.php | 6 +----- src/Psalm/Internal/Type/TypeParser.php | 2 +- src/Psalm/Type/Atomic/TClassStringMap.php | 2 +- src/Psalm/Type/Atomic/TGenericObject.php | 2 +- src/Psalm/Type/Atomic/TIterable.php | 2 +- src/Psalm/Type/Atomic/TNamedObject.php | 2 +- 30 files changed, 62 insertions(+), 111 deletions(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 867d0cfaf25..0fd50cb67cb 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -1614,7 +1614,7 @@ public function getCompletionItemsForPartialSymbol( $insertion_text = Type::getStringFromFQCLN( $fq_class_name, $aliases && $aliases->namespace ? $aliases->namespace : null, - $aliases ? $aliases->uses_flipped : [], + $aliases->uses_flipped ?? [], null ); diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 0165b2b67f3..3438aa5a913 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -2200,11 +2200,7 @@ public function addPreloadedStubFile(string $stub_file): void public function getPhpVersion(): ?string { - if (isset($this->configured_php_version)) { - return $this->configured_php_version; - } - - return $this->getPHPVersionFromComposerJson(); + return $this->configured_php_version ?? $this->getPHPVersionFromComposerJson(); } private function setBooleanAttribute(string $name, bool $value): void diff --git a/src/Psalm/Internal/Analyzer/CanAlias.php b/src/Psalm/Internal/Analyzer/CanAlias.php index eaa47fd211a..573125b8cfb 100644 --- a/src/Psalm/Internal/Analyzer/CanAlias.php +++ b/src/Psalm/Internal/Analyzer/CanAlias.php @@ -47,7 +47,7 @@ public function visitUse(PhpParser\Node\Stmt\Use_ $stmt): void foreach ($stmt->uses as $use) { $use_path = implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $stmt->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: @@ -107,7 +107,7 @@ public function visitGroupUse(PhpParser\Node\Stmt\GroupUse $stmt): void foreach ($stmt->uses as $use) { $use_path = $use_prefix . '\\' . implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $stmt->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index 3060b52c5ec..0d5116bc8bf 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -1913,9 +1913,7 @@ public static function analyzeClassMethodReturnType( ); } - $overridden_method_ids = isset($class_storage->overridden_method_ids[strtolower($stmt->name->name)]) - ? $class_storage->overridden_method_ids[strtolower($stmt->name->name)] - : []; + $overridden_method_ids = $class_storage->overridden_method_ids[strtolower($stmt->name->name)] ?? []; if (!$return_type && !$class_storage->is_interface @@ -2488,7 +2486,7 @@ private function checkParentClass( $code_location = new CodeLocation( $this, $extended_class, - $class_context ? $class_context->include_location : null, + $class_context->include_location ?? null, true ); @@ -2592,7 +2590,7 @@ private function checkParentClass( $code_location = new CodeLocation( $this, $class->name ?: $class, - $class_context ? $class_context->include_location : null, + $class_context->include_location ?? null, true ); diff --git a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php index 825a9f4b7b7..622cf8b158e 100644 --- a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php @@ -454,7 +454,7 @@ public function getFQCLN(): string public function getClassName(): ?string { - return $this->class->name ? $this->class->name->name : null; + return $this->class->name->name ?? null; } /** diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index c2ff4e629d3..8f583b69878 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -748,8 +748,8 @@ public static function checkReturnType( $fleshed_out_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $storage->return_type, - $classlike_storage ? $classlike_storage->name : null, - $classlike_storage ? $classlike_storage->name : null, + $classlike_storage->name ?? null, + $classlike_storage->name ?? null, $parent_class ); @@ -770,8 +770,8 @@ public static function checkReturnType( $fleshed_out_signature_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $storage->signature_return_type, - $classlike_storage ? $classlike_storage->name : null, - $classlike_storage ? $classlike_storage->name : null, + $classlike_storage->name ?? null, + $classlike_storage->name ?? null, $parent_class ); @@ -792,8 +792,8 @@ public static function checkReturnType( $fleshed_out_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $storage->return_type, - $classlike_storage ? $classlike_storage->name : null, - $classlike_storage ? $classlike_storage->name : null, + $classlike_storage->name ?? null, + $classlike_storage->name ?? null, $parent_class, true, true @@ -936,7 +936,7 @@ private static function addOrUpdateReturnType( true ), $inferred_return_type->canBeFullyExpressedInPhp($codebase->php_major_version, $codebase->php_minor_version), - $function_like_storage ? $function_like_storage->return_type_description : null + $function_like_storage->return_type_description ?? null ); } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index e4c51bec0a8..22b65571a21 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -253,12 +253,12 @@ private static function checkFunctionLikeTypeMatches( $param_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $param_type, - $classlike_storage ? $classlike_storage->name : null, - $static_classlike_storage ? $static_classlike_storage->name : null, + $classlike_storage->name ?? null, + $static_classlike_storage->name ?? null, $parent_class, true, false, - $static_classlike_storage ? $static_classlike_storage->final : false, + $static_classlike_storage->final ?? false, true ); @@ -384,12 +384,12 @@ private static function checkFunctionLikeTypeMatches( $param_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $param_type, - $classlike_storage ? $classlike_storage->name : null, - $static_classlike_storage ? $static_classlike_storage->name : null, + $classlike_storage->name ?? null, + $static_classlike_storage->name ?? null, $parent_class, true, false, - $static_classlike_storage ? $static_classlike_storage->final : false, + $static_classlike_storage->final ?? false, true ); } @@ -398,8 +398,8 @@ private static function checkFunctionLikeTypeMatches( ? \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $function_param->signature_type, - $classlike_storage ? $classlike_storage->name : null, - $static_classlike_storage ? $static_classlike_storage->name : null, + $classlike_storage->name ?? null, + $static_classlike_storage->name ?? null, $parent_class ) : null; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 998b6882e2c..796498e4201 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -619,7 +619,7 @@ public static function checkArgumentsMatch( $function_params[$i], $i, $i, - $function_storage ? $function_storage->allow_named_arg_calls : true, + $function_storage->allow_named_arg_calls ?? true, new VirtualArg( StubsGenerator::getExpressionFromType($default_type) ), @@ -627,7 +627,7 @@ public static function checkArgumentsMatch( $context, $class_generic_params, $template_result, - $function_storage ? $function_storage->specialize_call : true, + $function_storage->specialize_call ?? true, $in_call_map ); } @@ -795,13 +795,13 @@ public static function checkArgumentsMatch( $function_param, $argument_offset + $i, $i, - $function_storage ? $function_storage->allow_named_arg_calls : true, + $function_storage->allow_named_arg_calls ?? true, $arg, $arg_value_type, $context, $class_generic_params, $template_result, - $function_storage ? $function_storage->specialize_call : true, + $function_storage->specialize_call ?? true, $in_call_map ) === false) { return false; @@ -1363,12 +1363,12 @@ private static function getProvisionalTemplateResultForFunctionLike( $fleshed_out_param_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $function_param->type, - $class_storage ? $class_storage->name : null, - $calling_class_storage ? $calling_class_storage->name : null, + $class_storage->name ?? null, + $calling_class_storage->name ?? null, null, true, false, - $calling_class_storage ? $calling_class_storage->final : false + $calling_class_storage->final ?? false ); TemplateStandinTypeReplacer::replace( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php index 803e902b58c..51a99a1fcca 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php @@ -127,10 +127,7 @@ public static function analyze( // Oldest ancestor is at end of array $oldest_ancestor_declaring_method_id = array_pop($overridden_method_ids); } - $oldest_ancestor_declaring_method_class = null; - if ($oldest_ancestor_declaring_method_id) { - $oldest_ancestor_declaring_method_class = $oldest_ancestor_declaring_method_id->fq_class_name; - } + $oldest_ancestor_declaring_method_class = $oldest_ancestor_declaring_method_id->fq_class_name ?? null; switch ($visibility) { case ClassLikeAnalyzer::VISIBILITY_PUBLIC: diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php index a55dd9a3d92..dd0dd1ed164 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php @@ -330,17 +330,13 @@ public static function handle( ) { $stmt_assertions = $statements_analyzer->node_data->getAssertions($stmt); - if ($stmt_assertions !== null) { - $anded_assertions = $stmt_assertions; - } else { - $anded_assertions = AssertionFinder::processFunctionCall( + $anded_assertions = $stmt_assertions ?? AssertionFinder::processFunctionCall( $stmt, $context->self, $statements_analyzer, $codebase, $context->inside_negation ); - } $changed_vars = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index b7331d6fbe6..c1dfe47a516 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -315,7 +315,7 @@ public static function checkMethodArgs( $args, $method_params, (string) $method_id, - $method_storage ? $method_storage->allow_named_arg_calls : true, + $method_storage->allow_named_arg_calls ?? true, $context, $class_template_result ) === false) { @@ -414,11 +414,11 @@ public static function getTemplateTypesForCall( $codebase, $type, $appearing_class_name, - $calling_class_storage ? $calling_class_storage->name : null, + $calling_class_storage->name ?? null, null, true, false, - $calling_class_storage ? $calling_class_storage->final : false + $calling_class_storage->final ?? false ); } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index 56e1ea91ee3..a2cc39f97a5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -80,7 +80,7 @@ public static function analyze( if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -106,7 +106,7 @@ public static function analyze( if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -131,7 +131,7 @@ public static function analyze( if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -181,7 +181,7 @@ public static function analyze( if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -234,7 +234,7 @@ public static function analyze( if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $stmt_expr_type ? $stmt_expr_type->parent_nodes : []; + $type->parent_nodes = $stmt_expr_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); diff --git a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php index 65791d9d752..31c39ba5d49 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php @@ -633,7 +633,7 @@ private static function potentiallyInferTypesOnClosureFromParentReturnType( $param->type = self::inferInnerClosureTypeFromParent( $statements_analyzer->getCodebase(), $param->type, - $parent_param ? $parent_param->type : null + $parent_param->type ?? null ); } diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 80c0bfb9c6f..ff1d3a42bab 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -558,7 +558,7 @@ private static function analyzeStatement( $class_analyzer = new ClassAnalyzer( $stmt, $statements_analyzer->source, - $stmt->name ? $stmt->name->name : null + $stmt->name->name ?? null ); $class_analyzer->analyze(null, $global_context); diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index ccd0bbfb09c..63cb57d4b7a 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -316,7 +316,7 @@ function (string $file_path) : bool { $project_analyzer->prepareMigration(); - $files_to_update = $this->files_to_update !== null ? $this->files_to_update : $this->files_to_analyze; + $files_to_update = $this->files_to_update ?? $this->files_to_analyze; foreach ($files_to_update as $file_path) { $this->updateFile($file_path, $project_analyzer->dry_run); diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index 1a928fe7eca..2550677b4ed 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -360,7 +360,7 @@ public function getMethodParams( if (InternalCallMapHandler::inCallMap((string) $callmap_id)) { $class_storage = $this->classlike_storage_provider->get($callmap_id->fq_class_name); - $declaring_method_name = $declaring_method_id ? $declaring_method_id->method_name : $method_name; + $declaring_method_name = $declaring_method_id->method_name ?? $method_name; if (!$class_storage->stubbed || empty($class_storage->methods[$declaring_method_name]->stubbed)) { $function_callables = InternalCallMapHandler::getCallablesFromCallMap((string) $callmap_id); @@ -1060,11 +1060,7 @@ public function getAppearingMethodId( $method_name = $method_id->method_name; - if (isset($class_storage->appearing_method_ids[$method_name])) { - return $class_storage->appearing_method_ids[$method_name]; - } - - return null; + return $class_storage->appearing_method_ids[$method_name] ?? null; } /** @@ -1075,11 +1071,7 @@ public function getOverriddenMethodIds(MethodIdentifier $method_id): array $class_storage = $this->classlike_storage_provider->get($method_id->fq_class_name); $method_name = $method_id->method_name; - if (isset($class_storage->overridden_method_ids[$method_name])) { - return $class_storage->overridden_method_ids[$method_name]; - } - - return []; + return $class_storage->overridden_method_ids[$method_name] ?? []; } public function getCasedMethodId(MethodIdentifier $original_method_id): string diff --git a/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php b/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php index e86990cd734..f3c6e37839d 100644 --- a/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php +++ b/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php @@ -169,11 +169,7 @@ public static function addVarAnnotationToRemove(CodeLocation\DocblockTypeLocatio */ public static function getManipulationsForFile(string $file_path): array { - if (!isset(self::$file_manipulations[$file_path])) { - return []; - } - - return self::$file_manipulations[$file_path]; + return self::$file_manipulations[$file_path] ?? []; } /** diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php b/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php index 5b7dad78a16..31510534289 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php @@ -36,11 +36,7 @@ public static function resolve( $args = []; foreach ($stmt->args as $arg_node) { - $key = null; - - if ($arg_node->name) { - $key = $arg_node->name->name; - } + $key = $arg_node->name->name ?? null; $const_type = SimpleTypeInferer::infer( $codebase, diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index 9ab240259a2..11a9b167d7e 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -1385,7 +1385,7 @@ private function visitPropertyDeclaration( ); } - $doc_var_group_type = $var_comment ? $var_comment->type : null; + $doc_var_group_type = $var_comment->type ?? null; if ($doc_var_group_type) { $doc_var_group_type->queueClassLikesForScanning($this->codebase, $this->file_storage); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index f4c8c441a89..fb518a1a476 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -292,7 +292,7 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal $cond_id, $cond_id, $function_stmt->cond, - $this->classlike_storage ? $this->classlike_storage->name : null, + $this->classlike_storage->name ?? null, $this->file_scanner, null ); diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 75a3f994d2a..9c09600420b 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -424,7 +424,7 @@ private function handleUse(PhpParser\Node\Stmt\Use_ $node) : void foreach ($node->uses as $use) { $use_path = implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $node->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: @@ -457,7 +457,7 @@ private function handleGroupUse(PhpParser\Node\Stmt\GroupUse $node) : void foreach ($node->uses as $use) { $use_path = $use_prefix . '\\' . implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $node->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: diff --git a/src/Psalm/Internal/Provider/FakeFileProvider.php b/src/Psalm/Internal/Provider/FakeFileProvider.php index 596fecd9d24..7d693ec4732 100644 --- a/src/Psalm/Internal/Provider/FakeFileProvider.php +++ b/src/Psalm/Internal/Provider/FakeFileProvider.php @@ -29,11 +29,7 @@ public function getContents(string $file_path, bool $go_to_source = false): stri return $this->temp_files[strtolower($file_path)]; } - if (isset($this->fake_files[$file_path])) { - return $this->fake_files[$file_path]; - } - - return parent::getContents($file_path); + return $this->fake_files[$file_path] ?? parent::getContents($file_path); } public function setContents(string $file_path, string $file_contents): void @@ -50,11 +46,7 @@ public function setOpenContents(string $file_path, string $file_contents): void public function getModifiedTime(string $file_path): int { - if (isset($this->fake_file_times[$file_path])) { - return $this->fake_file_times[$file_path]; - } - - return parent::getModifiedTime($file_path); + return $this->fake_file_times[$file_path] ?? parent::getModifiedTime($file_path); } /** diff --git a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php index 3a0b6227b30..26e65fd2132 100644 --- a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php @@ -321,7 +321,7 @@ public static function getCallableFromAtomic( $matching_callable->is_pure = $codebase->functions->isCallMapFunctionPure( $codebase, - $statements_analyzer ? $statements_analyzer->node_data : null, + $statements_analyzer->node_data ?? null, $input_type_part->value, null, $must_use diff --git a/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php b/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php index 4fe35a4f981..33607b97c71 100644 --- a/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php @@ -81,15 +81,7 @@ public static function isContainedByUnion( return false; } - if ($result_reduction === null) { - //inconclusive result, we can't remove atomics anymore. - //container: `int<1, 5>`, input: `int<0, 6>` - //container: `5`, input: `int<4, 6>` - //we assume there's no combinations that makes the input contained - return false; - } - - return $result_reduction; + return $result_reduction ?? false; } /** diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index 799ef0bad55..5223e1126a0 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -1174,11 +1174,7 @@ public static function getMappedGenericTypeParams( \array_keys($input_class_storage->template_types) ); - if (!isset($input_type_params[$old_params_offset])) { - $candidate_param_type = \Psalm\Type::getMixed(); - } else { - $candidate_param_type = $input_type_params[$old_params_offset]; - } + $candidate_param_type = $input_type_params[$old_params_offset] ?? \Psalm\Type::getMixed(); } else { $candidate_param_type = new Union([clone $et]); } diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index afc35d2601f..ab0da4d455b 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -406,7 +406,7 @@ private static function getGenericParamClass( return new Atomic\TTemplateParamClass( $t->param_name, - $t_atomic_type ? $t_atomic_type->value : 'object', + $t_atomic_type->value ?? 'object', $t_atomic_type, $t->defining_class ); diff --git a/src/Psalm/Type/Atomic/TClassStringMap.php b/src/Psalm/Type/Atomic/TClassStringMap.php index a9b060d9f50..70e3b05466a 100644 --- a/src/Psalm/Type/Atomic/TClassStringMap.php +++ b/src/Psalm/Type/Atomic/TClassStringMap.php @@ -234,7 +234,7 @@ public function getStandinKeyParam() : Type\Union return new Type\Union([ new TTemplateParamClass( $this->param_name, - $this->as_type ? $this->as_type->value : 'object', + $this->as_type->value ?? 'object', $this->as_type, 'class-string-map' ) diff --git a/src/Psalm/Type/Atomic/TGenericObject.php b/src/Psalm/Type/Atomic/TGenericObject.php index f6b387015fd..20e4e31f33b 100644 --- a/src/Psalm/Type/Atomic/TGenericObject.php +++ b/src/Psalm/Type/Atomic/TGenericObject.php @@ -98,6 +98,6 @@ public function getAssertionString(bool $exact = false): string public function getChildNodes() : array { - return array_merge($this->type_params, $this->extra_types !== null ? $this->extra_types : []); + return array_merge($this->type_params, $this->extra_types ?? []); } } diff --git a/src/Psalm/Type/Atomic/TIterable.php b/src/Psalm/Type/Atomic/TIterable.php index c00215c66ba..9169cee9ee2 100644 --- a/src/Psalm/Type/Atomic/TIterable.php +++ b/src/Psalm/Type/Atomic/TIterable.php @@ -121,6 +121,6 @@ public function equals(Atomic $other_type, bool $ensure_source_equality): bool public function getChildNodes() : array { - return array_merge($this->type_params, $this->extra_types !== null ? $this->extra_types : []); + return array_merge($this->type_params, $this->extra_types ?? []); } } diff --git a/src/Psalm/Type/Atomic/TNamedObject.php b/src/Psalm/Type/Atomic/TNamedObject.php index feb7de18d94..f9bac893594 100644 --- a/src/Psalm/Type/Atomic/TNamedObject.php +++ b/src/Psalm/Type/Atomic/TNamedObject.php @@ -144,6 +144,6 @@ public function replaceTemplateTypesWithArgTypes( public function getChildNodes() : array { - return $this->extra_types !== null ? $this->extra_types : []; + return $this->extra_types ?? []; } } From 2315316b171ecd80f0b10c643912784243627568 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:01:35 +0200 Subject: [PATCH 26/33] return types --- .../Analyzer/Statements/Expression/AssertionFinder.php | 4 ++-- .../Statements/Expression/Call/FunctionCallAnalyzer.php | 2 +- .../Expression/Call/Method/AtomicMethodCallAnalyzer.php | 4 ++-- .../PhpVisitor/Reflector/FunctionLikeDocblockParser.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 37aad0f5d60..c1ccd6a2748 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -2114,7 +2114,7 @@ private static function getFalseInequalityAssertions( ?Codebase $codebase, bool $inside_negation, int $false_position - ) { + ): array { $if_types = []; if ($false_position === self::ASSIGNMENT_TO_RIGHT) { @@ -2807,7 +2807,7 @@ private static function getTrueEqualityAssertions( bool $inside_negation, bool $cache, int $true_position - ) { + ): array { $if_types = []; if ($true_position === self::ASSIGNMENT_TO_RIGHT) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php index 4c43208d33b..9beaff7385e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php @@ -352,7 +352,7 @@ private static function handleNamedFunction( PhpParser\Node\Name $function_name, Context $context, CodeLocation $code_location - ) { + ): FunctionCallInfo { $function_call_info = new FunctionCallInfo(); $codebase = $statements_analyzer->getCodebase(); 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 ab58381d33a..eb187adf363 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php @@ -660,7 +660,7 @@ private static function handleTemplatedMixins( PhpParser\Node\Expr\MethodCall $stmt, StatementsAnalyzer $statements_analyzer, string $fq_class_name - ) { + ): array { $naive_method_exists = false; if ($class_storage->templatedMixins @@ -749,7 +749,7 @@ private static function handleRegularMixins( StatementsAnalyzer $statements_analyzer, string $fq_class_name, ?string $lhs_var_id - ) { + ): array { $naive_method_exists = false; foreach ($class_storage->namedMixins as $mixin) { diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php index 7f0aab3eabc..92980e3de6c 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php @@ -490,7 +490,7 @@ public static function parse(PhpParser\Comment\Doc $comment): FunctionDocblockCo * @param list $line_parts * @return array{string, string} $line_parts */ - private static function sanitizeAssertionLineParts(array $line_parts) + private static function sanitizeAssertionLineParts(array $line_parts): array { if (count($line_parts) < 2 || strpos($line_parts[1], '$') === false) { throw new IncorrectDocblockException('Misplaced variable'); From 9170b0af8f29ff014090a9b625a74d20bcc24b6e Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:11:26 +0200 Subject: [PATCH 27/33] replace list() --- .../Expression/Call/FunctionCallReturnTypeFetcher.php | 2 +- .../PhpVisitor/Reflector/FunctionLikeDocblockScanner.php | 2 +- src/Psalm/Internal/Type/AssertionReconciler.php | 2 +- src/Psalm/Internal/Type/NegatedAssertionReconciler.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php index 1829db05220..1da0a389345 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php @@ -222,7 +222,7 @@ public static function fetch( $fake_call_factory = new BuilderFactory(); if (strpos($proxy_call['fqn'], '::') !== false) { - list($fqcn, $method) = explode('::', $proxy_call['fqn']); + [$fqcn, $method] = explode('::', $proxy_call['fqn']); $fake_call = $fake_call_factory->staticCall($fqcn, $method, $fake_call_arguments); } else { $fake_call = $fake_call_factory->funcCall($proxy_call['fqn'], $fake_call_arguments); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php index 5015b2528d1..d281fa986cf 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php @@ -987,7 +987,7 @@ private static function handleTaintFlow( if (isset($flow_parts[0]) && \strpos(trim($flow_parts[0]), 'proxy') === 0) { $proxy_call = trim(substr($flow_parts[0], strlen('proxy'))); - list($fully_qualified_name, $source_param_string) = explode('(', $proxy_call, 2); + [$fully_qualified_name, $source_param_string] = explode('(', $proxy_call, 2); if (!empty($fully_qualified_name) && !empty($source_param_string)) { $source_params = preg_split('/, ?/', substr($source_param_string, 0, -1)) ?: []; diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 2fc30291f6f..e7d47ad1a3c 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -1240,7 +1240,7 @@ private static function handleLiteralEquality( } } } elseif ($scalar_type === 'enum') { - list($fq_enum_name, $case_name) = explode('::', $value); + [$fq_enum_name, $case_name] = explode('::', $value); if ($existing_var_type->hasMixed()) { if ($is_loose_equality) { diff --git a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php index 2c11ee93c57..164d21399bb 100644 --- a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php @@ -462,7 +462,7 @@ private static function handleLiteralNegatedEquality( $scalar_var_type = Type::getFloat((float) $scalar_value); } } elseif ($scalar_type === 'enum') { - list($fq_enum_name, $case_name) = explode('::', substr($assertion, $bracket_pos + 1, -1)); + [$fq_enum_name, $case_name] = explode('::', substr($assertion, $bracket_pos + 1, -1)); foreach ($existing_var_type->getAtomicTypes() as $atomic_key => $atomic_type) { if (get_class($atomic_type) === Type\Atomic\TNamedObject::class From c91bdfb689e5a6183f4f03f361ace08b20943791 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:18:47 +0200 Subject: [PATCH 28/33] old casts --- src/Psalm/Config.php | 2 +- src/Psalm/Internal/Fork/Pool.php | 12 ++++++------ src/Psalm/Type/Union.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 3438aa5a913..bf2686819df 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -978,7 +978,7 @@ private static function fromXmlAndPaths( } if (isset($config_xml['maxStringLength'])) { - $attribute_text = intval($config_xml['maxStringLength']); + $attribute_text = (int)$config_xml['maxStringLength']; $config->max_string_length = $attribute_text; } diff --git a/src/Psalm/Internal/Fork/Pool.php b/src/Psalm/Internal/Fork/Pool.php index 21ef1e43239..2facc1111e9 100644 --- a/src/Psalm/Internal/Fork/Pool.php +++ b/src/Psalm/Internal/Fork/Pool.php @@ -307,7 +307,7 @@ private function readResultsFromChildren(): array // resource id. $streams = []; foreach ($this->read_streams as $stream) { - $streams[intval($stream)] = $stream; + $streams[(int)$stream] = $stream; } // Create an array for the content received on each stream, @@ -340,12 +340,12 @@ private function readResultsFromChildren(): array foreach ($needs_read as $file) { $buffer = fread($file, 1024); if ($buffer !== false) { - $content[intval($file)] .= $buffer; + $content[(int)$file] .= $buffer; } if (strpos($buffer, "\n") !== false) { - $serialized_messages = explode("\n", $content[intval($file)]); - $content[intval($file)] = array_pop($serialized_messages); + $serialized_messages = explode("\n", $content[(int)$file]); + $content[(int)$file] = array_pop($serialized_messages); foreach ($serialized_messages as $serialized_message) { $message = unserialize(base64_decode($serialized_message, true)); @@ -375,13 +375,13 @@ private function readResultsFromChildren(): array // If the stream has closed, stop trying to select on it. if (feof($file)) { - if ($content[intval($file)] !== '') { + if ($content[(int)$file] !== '') { error_log('Child did not send full message before closing the connection'); $this->did_have_error = true; } fclose($file); - unset($streams[intval($file)]); + unset($streams[(int)$file]); } } } diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 50564eaeca9..9c4bfb74be0 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -336,7 +336,7 @@ public function __toString(): string $printed_int = true; } - $types[] = strval($type); + $types[] = (string)$type; } sort($types); @@ -374,7 +374,7 @@ public function getKey() : string $types[] = 'int'; $printed_int = true; } else { - $types[] = strval($type->getKey()); + $types[] = (string)$type->getKey(); } } @@ -390,7 +390,7 @@ public function getId(): string $types = []; foreach ($this->types as $type) { - $types[] = strval($type->getId()); + $types[] = (string)$type->getId(); } sort($types); From 4577a11a2f78be659cfaf3c999039d9dee5b21e2 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:18:56 +0200 Subject: [PATCH 29/33] imports --- src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php | 1 + src/Psalm/Internal/Stubs/Generator/StubsGenerator.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php b/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php index a1044f89d8b..55d19edca73 100644 --- a/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php +++ b/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php @@ -16,6 +16,7 @@ use Psalm\Internal\Analyzer\ClassLikeAnalyzer; use Psalm\Internal\Scanner\ParsedDocblock; use Psalm\Type; +use function array_slice; class ClassLikeStubGenerator { diff --git a/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php b/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php index e57c180b24f..efce50c0472 100644 --- a/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php +++ b/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php @@ -22,6 +22,7 @@ use Psalm\Node\VirtualNullableType; use Psalm\Node\VirtualParam; use Psalm\Type; +use function dirname; class StubsGenerator { From 5d6d3df4cf22067770f594fa6e09d584b613735f Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:20:01 +0200 Subject: [PATCH 30/33] unnecessary identical child method --- .../Analyzer/FunctionLikeAnalyzer.php | 20 ----------------- src/Psalm/Type/Atomic/TCallableArray.php | 4 ---- src/Psalm/Type/Atomic/TIntMask.php | 13 ----------- src/Psalm/Type/Atomic/TIntMaskOf.php | 13 ----------- src/Psalm/Type/Atomic/TIntRange.php | 13 ----------- src/Psalm/Type/Atomic/TLiteralFloat.php | 13 ----------- src/Psalm/Type/Atomic/TLiteralInt.php | 13 ----------- src/Psalm/Type/Atomic/TLiteralString.php | 18 --------------- src/Psalm/Type/Atomic/TLowercaseString.php | 5 ----- .../Type/Atomic/TNonEmptyLowercaseString.php | 5 ----- .../TNonEmptyNonspecificLiteralString.php | 5 ----- .../Type/Atomic/TNonspecificLiteralInt.php | 5 ----- .../Type/Atomic/TNonspecificLiteralString.php | 5 ----- .../Type/Atomic/TTemplateIndexedAccess.php | 12 ---------- src/Psalm/Type/Atomic/TTemplateKeyOf.php | 21 ------------------ src/Psalm/Type/Atomic/TTemplateParamClass.php | 22 ------------------- src/Psalm/Type/Atomic/TTypeAlias.php | 13 ----------- 17 files changed, 200 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 524a204ca4d..0cf5923e053 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -1624,16 +1624,6 @@ public function getAliasedClassesFlippedReplaceable(): array return []; } - public function getFQCLN(): ?string - { - return $this->source->getFQCLN(); - } - - public function getClassName(): ?string - { - return $this->source->getClassName(); - } - /** * @return array>|null */ @@ -1647,16 +1637,6 @@ public function getTemplateTypeMap(): ?array return $this->storage->template_types; } - public function getParentFQCLN(): ?string - { - return $this->source->getParentFQCLN(); - } - - public function getNodeTypeProvider() : \Psalm\NodeTypeProvider - { - return $this->source->getNodeTypeProvider(); - } - public function isStatic(): bool { return $this->is_static; diff --git a/src/Psalm/Type/Atomic/TCallableArray.php b/src/Psalm/Type/Atomic/TCallableArray.php index aa484aa89dc..5caffc5954c 100644 --- a/src/Psalm/Type/Atomic/TCallableArray.php +++ b/src/Psalm/Type/Atomic/TCallableArray.php @@ -11,8 +11,4 @@ class TCallableArray extends TNonEmptyArray */ public $value = 'callable-array'; - public function getKey(bool $include_extra = true): string - { - return 'array'; - } } diff --git a/src/Psalm/Type/Atomic/TIntMask.php b/src/Psalm/Type/Atomic/TIntMask.php index 95a08d4447a..abb1e0cbfe7 100644 --- a/src/Psalm/Type/Atomic/TIntMask.php +++ b/src/Psalm/Type/Atomic/TIntMask.php @@ -40,19 +40,6 @@ public function getId(bool $nested = false): string return 'int-mask<' . substr($s, 0, -2) . '>'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TIntMaskOf.php b/src/Psalm/Type/Atomic/TIntMaskOf.php index 27e3f80a545..de4f36c296c 100644 --- a/src/Psalm/Type/Atomic/TIntMaskOf.php +++ b/src/Psalm/Type/Atomic/TIntMaskOf.php @@ -29,19 +29,6 @@ public function getId(bool $nested = false): string return $this->getKey(); } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes */ diff --git a/src/Psalm/Type/Atomic/TIntRange.php b/src/Psalm/Type/Atomic/TIntRange.php index 002a09925b3..0f8032e3871 100644 --- a/src/Psalm/Type/Atomic/TIntRange.php +++ b/src/Psalm/Type/Atomic/TIntRange.php @@ -42,19 +42,6 @@ public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_ return false; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes */ diff --git a/src/Psalm/Type/Atomic/TLiteralFloat.php b/src/Psalm/Type/Atomic/TLiteralFloat.php index 062603803c0..7b2ce34a887 100644 --- a/src/Psalm/Type/Atomic/TLiteralFloat.php +++ b/src/Psalm/Type/Atomic/TLiteralFloat.php @@ -24,19 +24,6 @@ public function getId(bool $nested = false): string return 'float(' . $this->value . ')'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'float' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TLiteralInt.php b/src/Psalm/Type/Atomic/TLiteralInt.php index 1666ca85ced..1b0abec1b8d 100644 --- a/src/Psalm/Type/Atomic/TLiteralInt.php +++ b/src/Psalm/Type/Atomic/TLiteralInt.php @@ -29,19 +29,6 @@ public function getAssertionString(bool $exact = false): string return 'int(' . $this->value . ')'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TLiteralString.php b/src/Psalm/Type/Atomic/TLiteralString.php index e16aa54c464..e59c92e414f 100644 --- a/src/Psalm/Type/Atomic/TLiteralString.php +++ b/src/Psalm/Type/Atomic/TLiteralString.php @@ -23,11 +23,6 @@ public function getKey(bool $include_extra = true) : string return 'string(' . $this->value . ')'; } - public function __toString(): string - { - return 'string'; - } - public function getId(bool $nested = false): string { // quote control characters, backslashes and double quote @@ -44,19 +39,6 @@ public function getAssertionString(bool $exact = false): string return 'string(' . $this->value . ')'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'string' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TLowercaseString.php b/src/Psalm/Type/Atomic/TLowercaseString.php index cb78b520061..b8414be8c21 100644 --- a/src/Psalm/Type/Atomic/TLowercaseString.php +++ b/src/Psalm/Type/Atomic/TLowercaseString.php @@ -3,11 +3,6 @@ class TLowercaseString extends TString { - public function getKey(bool $include_extra = true): string - { - return 'string'; - } - public function getId(bool $nested = false): string { return 'lowercase-string'; diff --git a/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php b/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php index d0132401372..3ab6ab6bf6b 100644 --- a/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php +++ b/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php @@ -6,11 +6,6 @@ */ class TNonEmptyLowercaseString extends TNonEmptyString { - public function getKey(bool $include_extra = true): string - { - return 'string'; - } - public function getId(bool $nested = false): string { return 'non-empty-lowercase-string'; diff --git a/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php b/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php index 4b6f5657ac4..9eee2fd1f9c 100644 --- a/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php +++ b/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php @@ -7,11 +7,6 @@ */ class TNonEmptyNonspecificLiteralString extends TNonspecificLiteralString { - public function getKey(bool $include_extra = true): string - { - return 'string'; - } - public function getId(bool $nested = false): string { return 'non-empty-literal-string'; diff --git a/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php b/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php index 99e20ef0481..09481333a4f 100644 --- a/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php +++ b/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php @@ -12,11 +12,6 @@ public function __toString(): string return 'literal-int'; } - public function getKey(bool $include_extra = true) : string - { - return 'int'; - } - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool { return false; diff --git a/src/Psalm/Type/Atomic/TNonspecificLiteralString.php b/src/Psalm/Type/Atomic/TNonspecificLiteralString.php index 5a688b5968d..4d57f63782e 100644 --- a/src/Psalm/Type/Atomic/TNonspecificLiteralString.php +++ b/src/Psalm/Type/Atomic/TNonspecificLiteralString.php @@ -12,11 +12,6 @@ public function __toString(): string return 'literal-string'; } - public function getKey(bool $include_extra = true) : string - { - return 'string'; - } - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool { return false; diff --git a/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php b/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php index 517e12ff5e0..c64dec91c44 100644 --- a/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php +++ b/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php @@ -61,16 +61,4 @@ public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_ return false; } - /** - * @param array $aliased_classes - * - */ - public function toNamespacedString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - bool $use_phpdoc_format - ): string { - return $this->getKey(); - } } diff --git a/src/Psalm/Type/Atomic/TTemplateKeyOf.php b/src/Psalm/Type/Atomic/TTemplateKeyOf.php index 09958050bbf..f0982d0393e 100644 --- a/src/Psalm/Type/Atomic/TTemplateKeyOf.php +++ b/src/Psalm/Type/Atomic/TTemplateKeyOf.php @@ -48,27 +48,6 @@ public function getId(bool $nested = false): string return 'key-of<' . $this->param_name . ':' . $this->defining_class . ' as ' . $this->as->getId() . '>'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return null; - } - - /** - * @return false - */ - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool - { - return false; - } - /** * @param array $aliased_classes */ diff --git a/src/Psalm/Type/Atomic/TTemplateParamClass.php b/src/Psalm/Type/Atomic/TTemplateParamClass.php index 6dca3507dd1..3464dfe6b4c 100644 --- a/src/Psalm/Type/Atomic/TTemplateParamClass.php +++ b/src/Psalm/Type/Atomic/TTemplateParamClass.php @@ -49,24 +49,6 @@ public function getAssertionString(bool $exact = false): string return 'class-string<' . $this->param_name . '>'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return 'string'; - } - - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool - { - return false; - } - /** * @param array $aliased_classes * @@ -80,8 +62,4 @@ public function toNamespacedString( return $this->param_name . '::class'; } - public function getChildNodes() : array - { - return $this->as_type ? [$this->as_type] : []; - } } diff --git a/src/Psalm/Type/Atomic/TTypeAlias.php b/src/Psalm/Type/Atomic/TTypeAlias.php index 197afd0a1f1..1003c288c4e 100644 --- a/src/Psalm/Type/Atomic/TTypeAlias.php +++ b/src/Psalm/Type/Atomic/TTypeAlias.php @@ -78,19 +78,6 @@ public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_ return false; } - /** - * @param array $aliased_classes - * - */ - public function toNamespacedString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - bool $use_phpdoc_format - ): string { - return $this->getKey(); - } - public function getAssertionString(bool $exact = false): string { return 'mixed'; From db395d56056919dbc1f4d7bbf3074af3ca154eea Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:22:35 +0200 Subject: [PATCH 31/33] unnecessary cast --- src/Psalm/Type/Union.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 9c4bfb74be0..66d541333a4 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -374,7 +374,7 @@ public function getKey() : string $types[] = 'int'; $printed_int = true; } else { - $types[] = (string)$type->getKey(); + $types[] = $type->getKey(); } } @@ -390,7 +390,7 @@ public function getId(): string $types = []; foreach ($this->types as $type) { - $types[] = (string)$type->getId(); + $types[] = $type->getId(); } sort($types); From 38dac34846461ea67b39c58d5b45215af8bedc6e Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:24:07 +0200 Subject: [PATCH 32/33] unnecessary null initialization --- src/Psalm/Codebase.php | 4 ++-- src/Psalm/Config.php | 6 +++--- src/Psalm/Config/ProjectFileFilter.php | 2 +- src/Psalm/Context.php | 14 +++++++------- .../Expression/Call/FunctionCallInfo.php | 10 +++++----- .../Internal/Analyzer/StatementsAnalyzer.php | 4 ++-- src/Psalm/Internal/Codebase/Analyzer.php | 2 +- .../Internal/Codebase/InternalCallMapHandler.php | 6 +++--- .../LanguageServer/ProtocolStreamReader.php | 2 +- .../Internal/PhpVisitor/ReflectorVisitor.php | 2 +- src/Psalm/Internal/PluginManager/PluginList.php | 4 ++-- .../Internal/Provider/FileReferenceProvider.php | 2 +- .../Internal/Provider/ParserCacheProvider.php | 2 +- .../Internal/Provider/ProjectCacheProvider.php | 4 ++-- .../Scanner/ClassLikeDocblockComment.php | 4 ++-- .../Internal/Scanner/FunctionDocblockComment.php | 10 +++++----- .../Internal/Scanner/VarDocblockComment.php | 4 ++-- src/Psalm/Internal/Scope/IfScope.php | 10 +++++----- src/Psalm/Internal/Scope/LoopScope.php | 2 +- src/Psalm/Internal/Scope/SwitchScope.php | 10 +++++----- .../Type/Comparator/TypeComparisonResult.php | 16 ++++++++-------- src/Psalm/Internal/Type/TypeCombination.php | 6 +++--- src/Psalm/Storage/ClassConstantStorage.php | 2 +- src/Psalm/Storage/ClassLikeStorage.php | 2 +- src/Psalm/Storage/MethodStorage.php | 4 ++-- src/Psalm/Storage/PropertyStorage.php | 2 +- src/Psalm/Type/Atomic/TKeyedArray.php | 6 +++--- src/Psalm/Type/Union.php | 2 +- 28 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 0fd50cb67cb..256f5c5f1d3 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -95,7 +95,7 @@ class Codebase /** * @var null|'always'|'auto' */ - public $find_unused_code = null; + public $find_unused_code; /** * @var FileProvider @@ -179,7 +179,7 @@ class Codebase /** * @var ?Internal\Codebase\TaintFlowGraph */ - public $taint_flow_graph = null; + public $taint_flow_graph; /** * @var bool diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index bf2686819df..5b828d2cf4d 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -182,7 +182,7 @@ class Config * * @var bool|null */ - public $load_xdebug_stub = null; + public $load_xdebug_stub; /** * The directory to store PHP Parser (and other) caches @@ -288,7 +288,7 @@ class Config /** * @var ?bool */ - public $show_mixed_issues = null; + public $show_mixed_issues; /** @var bool */ public $strict_binary_operands = false; @@ -501,7 +501,7 @@ class Config public $hash = ''; /** @var string|null */ - public $error_baseline = null; + public $error_baseline; /** * @var bool diff --git a/src/Psalm/Config/ProjectFileFilter.php b/src/Psalm/Config/ProjectFileFilter.php index 6899e435d94..dc03681f08d 100644 --- a/src/Psalm/Config/ProjectFileFilter.php +++ b/src/Psalm/Config/ProjectFileFilter.php @@ -11,7 +11,7 @@ class ProjectFileFilter extends FileFilter /** * @var ProjectFileFilter|null */ - private $file_filter = null; + private $file_filter; /** * @return static diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 389b92ff3b3..34c74cabca3 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -103,7 +103,7 @@ class Context /** * @var null|CodeLocation */ - public $include_location = null; + public $include_location; /** * @var string|null @@ -194,7 +194,7 @@ class Context * * @var array|null */ - public $initialized_methods = null; + public $initialized_methods; /** * @var array @@ -290,27 +290,27 @@ class Context /** * @var Internal\Scope\LoopScope|null */ - public $loop_scope = null; + public $loop_scope; /** * @var Internal\Scope\CaseScope|null */ - public $case_scope = null; + public $case_scope; /** * @var Internal\Scope\FinallyScope|null */ - public $finally_scope = null; + public $finally_scope; /** * @var Context|null */ - public $if_context = null; + public $if_context; /** * @var \Psalm\Internal\Scope\IfScope|null */ - public $if_scope = null; + public $if_scope; /** * @var bool diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php index c27baff2593..70a193e8c7b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php @@ -12,12 +12,12 @@ class FunctionCallInfo /** * @var ?string */ - public $function_id = null; + public $function_id; /** * @var ?bool */ - public $function_exists = null; + public $function_exists; /** * @var bool @@ -42,17 +42,17 @@ class FunctionCallInfo /** * @var ?array */ - public $function_params = null; + public $function_params; /** * @var ?\Psalm\Storage\FunctionLikeStorage */ - public $function_storage = null; + public $function_storage; /** * @var ?PhpParser\Node\Name */ - public $new_function_name = null; + public $new_function_name; /** * @var bool diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index ff1d3a42bab..553e57498de 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -118,12 +118,12 @@ class StatementsAnalyzer extends SourceAnalyzer /** * @var ParsedDocblock|null */ - private $parsed_docblock = null; + private $parsed_docblock; /** * @var ?string */ - private $fake_this_class = null; + private $fake_this_class; /** @var \Psalm\Internal\Provider\NodeDataProvider */ public $node_data; diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 63cb57d4b7a..5797be13a82 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -148,7 +148,7 @@ class Analyzer * * @var array|null */ - private $files_to_update = null; + private $files_to_update; /** * @var array> diff --git a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php index e33eaffb077..8eb25195c01 100644 --- a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php +++ b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php @@ -32,16 +32,16 @@ class InternalCallMapHandler /** * @var ?int */ - private static $loaded_php_major_version = null; + private static $loaded_php_major_version; /** * @var ?int */ - private static $loaded_php_minor_version = null; + private static $loaded_php_minor_version; /** * @var array>|null */ - private static $call_map = null; + private static $call_map; /** * @var array>|null diff --git a/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php b/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php index d982d875e9b..cde108ce5d1 100644 --- a/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php +++ b/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php @@ -37,7 +37,7 @@ class ProtocolStreamReader implements ProtocolReader /** @var string[] */ private $headers = []; /** @var ?int */ - private $content_length = null; + private $content_length; /** @var bool */ private $did_emit_close = false; diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 9c09600420b..7d979358343 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -92,7 +92,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour /** * @var ?int */ - private $skip_if_descendants = null; + private $skip_if_descendants; /** * @var array diff --git a/src/Psalm/Internal/PluginManager/PluginList.php b/src/Psalm/Internal/PluginManager/PluginList.php index 2769bace785..916ecdc8e81 100644 --- a/src/Psalm/Internal/PluginManager/PluginList.php +++ b/src/Psalm/Internal/PluginManager/PluginList.php @@ -18,10 +18,10 @@ class PluginList private $composer_lock; /** @var ?array [pluginClass => packageName] */ - private $all_plugins = null; + private $all_plugins; /** @var ?array [pluginClass => ?packageName] */ - private $enabled_plugins = null; + private $enabled_plugins; public function __construct(?ConfigFile $config_file, ComposerLock $composer_lock) { diff --git a/src/Psalm/Internal/Provider/FileReferenceProvider.php b/src/Psalm/Internal/Provider/FileReferenceProvider.php index 42b033b9b48..6bd1c35ef06 100644 --- a/src/Psalm/Internal/Provider/FileReferenceProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceProvider.php @@ -78,7 +78,7 @@ class FileReferenceProvider * * @var array|null */ - private static $deleted_files = null; + private static $deleted_files; /** * A lookup table used for getting all the files referenced by a file diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index bde4314e281..8a8973f717f 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -45,7 +45,7 @@ class ParserCacheProvider * * @var array|null */ - private $existing_file_content_hashes = null; + private $existing_file_content_hashes; /** * A map of recently-added filename hashes to contents hashes diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index e0d9d7c143b..0aa52bf3664 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -21,12 +21,12 @@ class ProjectCacheProvider /** * @var int|null */ - private $last_run = null; + private $last_run; /** * @var string|null */ - private $composer_lock_hash = null; + private $composer_lock_hash; private $composer_lock_location; diff --git a/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php b/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php index f18f947f5f5..64f24ad5237 100644 --- a/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php +++ b/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php @@ -32,7 +32,7 @@ class ClassLikeDocblockComment * * @var null|string */ - public $psalm_internal = null; + public $psalm_internal; /** * @var string[] @@ -57,7 +57,7 @@ class ClassLikeDocblockComment /** * @var ?string */ - public $yield = null; + public $yield; /** * @var array diff --git a/src/Psalm/Internal/Scanner/FunctionDocblockComment.php b/src/Psalm/Internal/Scanner/FunctionDocblockComment.php index f3c8fda0a59..d0482c10ac2 100644 --- a/src/Psalm/Internal/Scanner/FunctionDocblockComment.php +++ b/src/Psalm/Internal/Scanner/FunctionDocblockComment.php @@ -9,22 +9,22 @@ class FunctionDocblockComment /** * @var string|null */ - public $return_type = null; + public $return_type; /** * @var string|null */ - public $return_type_description = null; + public $return_type_description; /** * @var int|null */ - public $return_type_start = null; + public $return_type_start; /** * @var int|null */ - public $return_type_end = null; + public $return_type_end; /** * @var int|null @@ -73,7 +73,7 @@ class FunctionDocblockComment * * @var null|string */ - public $psalm_internal = null; + public $psalm_internal; /** * Whether or not the function is internal diff --git a/src/Psalm/Internal/Scanner/VarDocblockComment.php b/src/Psalm/Internal/Scanner/VarDocblockComment.php index fb55108f54f..330848f7c8c 100644 --- a/src/Psalm/Internal/Scanner/VarDocblockComment.php +++ b/src/Psalm/Internal/Scanner/VarDocblockComment.php @@ -16,7 +16,7 @@ class VarDocblockComment /** * @var string|null */ - public $var_id = null; + public $var_id; /** * @var int|null @@ -52,7 +52,7 @@ class VarDocblockComment * * @var null|string */ - public $psalm_internal = null; + public $psalm_internal; /** * Whether or not the property is readonly diff --git a/src/Psalm/Internal/Scope/IfScope.php b/src/Psalm/Internal/Scope/IfScope.php index 98ee9074136..85fdc515e71 100644 --- a/src/Psalm/Internal/Scope/IfScope.php +++ b/src/Psalm/Internal/Scope/IfScope.php @@ -12,7 +12,7 @@ class IfScope /** * @var array|null */ - public $new_vars = null; + public $new_vars; /** * @var array @@ -22,12 +22,12 @@ class IfScope /** * @var array|null */ - public $redefined_vars = null; + public $redefined_vars; /** * @var array|null */ - public $assigned_var_ids = null; + public $assigned_var_ids; /** * @var array @@ -57,7 +57,7 @@ class IfScope /** * @var array|null */ - public $negatable_if_types = null; + public $negatable_if_types; /** * @var list @@ -78,7 +78,7 @@ class IfScope * * @var array|null */ - public $possible_param_types = null; + public $possible_param_types; /** * @var string[] diff --git a/src/Psalm/Internal/Scope/LoopScope.php b/src/Psalm/Internal/Scope/LoopScope.php index 2bbfe903b95..1e620410013 100644 --- a/src/Psalm/Internal/Scope/LoopScope.php +++ b/src/Psalm/Internal/Scope/LoopScope.php @@ -37,7 +37,7 @@ class LoopScope /** * @var array|null */ - public $possibly_redefined_loop_parent_vars = null; + public $possibly_redefined_loop_parent_vars; /** * @var array diff --git a/src/Psalm/Internal/Scope/SwitchScope.php b/src/Psalm/Internal/Scope/SwitchScope.php index 9025e65578a..0697d6fab5b 100644 --- a/src/Psalm/Internal/Scope/SwitchScope.php +++ b/src/Psalm/Internal/Scope/SwitchScope.php @@ -13,7 +13,7 @@ class SwitchScope /** * @var array|null */ - public $new_vars_in_scope = null; + public $new_vars_in_scope; /** * @var array @@ -23,12 +23,12 @@ class SwitchScope /** * @var array|null */ - public $redefined_vars = null; + public $redefined_vars; /** * @var array|null */ - public $possibly_redefined_vars = null; + public $possibly_redefined_vars; /** * @var array @@ -38,7 +38,7 @@ class SwitchScope /** * @var PhpParser\Node\Expr|null */ - public $leftover_case_equality_expr = null; + public $leftover_case_equality_expr; /** * @var list @@ -48,5 +48,5 @@ class SwitchScope /** * @var array|null */ - public $new_assigned_var_ids = null; + public $new_assigned_var_ids; } diff --git a/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php b/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php index 78f2698735a..288da07b9cb 100644 --- a/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php +++ b/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php @@ -5,26 +5,26 @@ class TypeComparisonResult { /** @var ?bool */ - public $scalar_type_match_found = null; + public $scalar_type_match_found; /** @var ?bool */ - public $type_coerced = null; + public $type_coerced; /** @var ?bool */ - public $type_coerced_from_mixed = null; + public $type_coerced_from_mixed; /** @var ?bool */ - public $type_coerced_from_as_mixed = null; + public $type_coerced_from_as_mixed; /** @var ?bool */ - public $to_string_cast = null; + public $to_string_cast; /** @var ?bool */ - public $type_coerced_from_scalar = null; + public $type_coerced_from_scalar; /** @var ?\Psalm\Type\Union */ - public $replacement_union_type = null; + public $replacement_union_type; /** @var ?\Psalm\Type\Atomic */ - public $replacement_atomic_type = null; + public $replacement_atomic_type; } diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index f2fd1dcc609..5bcb88e9527 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -46,10 +46,10 @@ class TypeCombination public $objectlike_sealed = true; /** @var ?Union */ - public $objectlike_key_type = null; + public $objectlike_key_type; /** @var ?Union */ - public $objectlike_value_type = null; + public $objectlike_value_type; /** @var bool */ public $empty_mixed = false; @@ -58,7 +58,7 @@ class TypeCombination public $non_empty_mixed = false; /** @var ?bool */ - public $mixed_from_loop_isset = null; + public $mixed_from_loop_isset; /** @var array|null */ public $strings = []; diff --git a/src/Psalm/Storage/ClassConstantStorage.php b/src/Psalm/Storage/ClassConstantStorage.php index 2185f6a805b..ac752dc1026 100644 --- a/src/Psalm/Storage/ClassConstantStorage.php +++ b/src/Psalm/Storage/ClassConstantStorage.php @@ -30,7 +30,7 @@ class ClassConstantStorage /** * @var ?\Psalm\Internal\Scanner\UnresolvedConstantComponent */ - public $unresolved_node = null; + public $unresolved_node; /** * @var bool diff --git a/src/Psalm/Storage/ClassLikeStorage.php b/src/Psalm/Storage/ClassLikeStorage.php index bf1164115d4..c7a533e96dc 100644 --- a/src/Psalm/Storage/ClassLikeStorage.php +++ b/src/Psalm/Storage/ClassLikeStorage.php @@ -54,7 +54,7 @@ class ClassLikeStorage /** * @var ?string */ - public $mixin_declaring_fqcln = null; + public $mixin_declaring_fqcln; /** * @var bool diff --git a/src/Psalm/Storage/MethodStorage.php b/src/Psalm/Storage/MethodStorage.php index 7591f18b980..becfc51d4eb 100644 --- a/src/Psalm/Storage/MethodStorage.php +++ b/src/Psalm/Storage/MethodStorage.php @@ -83,12 +83,12 @@ class MethodStorage extends FunctionLikeStorage /** * @var ?array */ - public $this_property_mutations = null; + public $this_property_mutations; /** * @var Type\Union|null */ - public $self_out_type = null; + public $self_out_type; /** * @var bool diff --git a/src/Psalm/Storage/PropertyStorage.php b/src/Psalm/Storage/PropertyStorage.php index 66917c3366a..2452f2b0c4a 100644 --- a/src/Psalm/Storage/PropertyStorage.php +++ b/src/Psalm/Storage/PropertyStorage.php @@ -84,7 +84,7 @@ class PropertyStorage /** * @var ?string */ - public $getter_method = null; + public $getter_method; /** * @var bool diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index dd5cb6b2545..8563f094413 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -32,7 +32,7 @@ class TKeyedArray extends \Psalm\Type\Atomic /** * @var array|null */ - public $class_strings = null; + public $class_strings; /** * @var bool - whether or not the objectlike has been created from an explicit array @@ -44,14 +44,14 @@ class TKeyedArray extends \Psalm\Type\Atomic * * @var ?Union */ - public $previous_key_type = null; + public $previous_key_type; /** * Whether or not to allow new properties to be asserted on the given array * * @var ?Union */ - public $previous_value_type = null; + public $previous_value_type; /** * @var bool - if this is a list of sequential elements diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 66d541333a4..deccebec9b7 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -80,7 +80,7 @@ class Union implements TypeNode * * @var ?string */ - public $initialized_class = null; + public $initialized_class; /** * Whether or not the type has been checked yet From ab6efe49b264af7eb57d03c69735171ae8e004bf Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 26 Sep 2021 23:41:26 +0200 Subject: [PATCH 33/33] fix CS --- src/Psalm/Config.php | 2 -- .../Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 2 +- src/Psalm/Internal/Analyzer/MethodComparator.php | 2 +- .../Analyzer/Statements/Block/SwitchCaseAnalyzer.php | 1 + .../Statements/Expression/AssignmentAnalyzer.php | 1 - .../Statements/Expression/Call/ArgumentsAnalyzer.php | 4 ++-- .../Expression/Call/NamedFunctionCallHandler.php | 12 ++++++------ .../Analyzer/Statements/Expression/CallAnalyzer.php | 2 +- src/Psalm/Internal/Cli/LanguageServer.php | 1 + src/Psalm/Internal/Codebase/DataFlowGraph.php | 1 + .../Internal/Codebase/InternalCallMapHandler.php | 1 + src/Psalm/Internal/Fork/Pool.php | 1 - .../Reflector/FunctionLikeDocblockParser.php | 1 + src/Psalm/Internal/Provider/StatementsProvider.php | 2 +- .../Type/SimpleNegatedAssertionReconciler.php | 1 + .../Internal/Type/TemplateInferredTypeReplacer.php | 2 +- src/Psalm/Internal/Type/TypeTokenizer.php | 1 - src/Psalm/Type/Atomic.php | 1 - src/Psalm/Type/Atomic/TCallableArray.php | 1 - src/Psalm/Type/Atomic/TTemplateIndexedAccess.php | 1 - src/Psalm/Type/Atomic/TTemplateParamClass.php | 1 - src/Psalm/Type/Union.php | 1 - 22 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 5b828d2cf4d..7f58038ed23 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -55,7 +55,6 @@ use function glob; use function implode; use function in_array; -use function intval; use function is_a; use function is_dir; use function is_file; @@ -80,7 +79,6 @@ use function strpos; use function strrpos; use function strtolower; -use function strtr; use function substr; use function substr_count; use function sys_get_temp_dir; diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 8f583b69878..eb0d8e49a21 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -41,8 +41,8 @@ use function array_diff; use function count; use function in_array; +use function strpos; use function strtolower; -use function substr; /** * @internal diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index af25360559d..154cb460fc8 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -26,8 +26,8 @@ use Psalm\Type; use function in_array; +use function strpos; use function strtolower; -use function substr; class MethodComparator { diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index ba4435446a3..1a7afc01eee 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -39,6 +39,7 @@ use function count; use function in_array; use function is_string; +use function strpos; use function substr; /** diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index d076a159252..07a61a2673d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -62,7 +62,6 @@ use function reset; use function strpos; use function strtolower; -use function substr; /** * @internal diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 796498e4201..454bdb0c337 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -795,13 +795,13 @@ public static function checkArgumentsMatch( $function_param, $argument_offset + $i, $i, - $function_storage->allow_named_arg_calls ?? true, + $function_storage->allow_named_arg_calls ?? true, $arg, $arg_value_type, $context, $class_generic_params, $template_result, - $function_storage->specialize_call ?? true, + $function_storage->specialize_call ?? true, $in_call_map ) === false) { return false; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php index dd0dd1ed164..73c271193c8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php @@ -331,12 +331,12 @@ public static function handle( $stmt_assertions = $statements_analyzer->node_data->getAssertions($stmt); $anded_assertions = $stmt_assertions ?? AssertionFinder::processFunctionCall( - $stmt, - $context->self, - $statements_analyzer, - $codebase, - $context->inside_negation - ); + $stmt, + $context->self, + $statements_analyzer, + $codebase, + $context->inside_negation + ); $changed_vars = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index c1dfe47a516..28d16d3f1ff 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -315,7 +315,7 @@ public static function checkMethodArgs( $args, $method_params, (string) $method_id, - $method_storage->allow_named_arg_calls ?? true, + $method_storage->allow_named_arg_calls ?? true, $context, $class_template_result ) === false) { diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index 390734278f0..b7d2d58d19a 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -27,6 +27,7 @@ use function preg_replace; use function realpath; use function setlocale; +use function strpos; use function strtolower; use function substr; diff --git a/src/Psalm/Internal/Codebase/DataFlowGraph.php b/src/Psalm/Internal/Codebase/DataFlowGraph.php index d8497bd7b2b..279e4c0e90b 100644 --- a/src/Psalm/Internal/Codebase/DataFlowGraph.php +++ b/src/Psalm/Internal/Codebase/DataFlowGraph.php @@ -10,6 +10,7 @@ use function array_reverse; use function array_sum; use function strlen; +use function strpos; use function substr; abstract class DataFlowGraph diff --git a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php index 8eb25195c01..f79ef431b81 100644 --- a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php +++ b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php @@ -14,6 +14,7 @@ use function count; use function dirname; use function file_exists; +use function strpos; use function strtolower; use function substr; use function version_compare; diff --git a/src/Psalm/Internal/Fork/Pool.php b/src/Psalm/Internal/Fork/Pool.php index 2facc1111e9..c9409f10ffa 100644 --- a/src/Psalm/Internal/Fork/Pool.php +++ b/src/Psalm/Internal/Fork/Pool.php @@ -21,7 +21,6 @@ use function gettype; use function in_array; use function ini_get; -use function intval; use function pcntl_fork; use function pcntl_waitpid; use function pcntl_wexitstatus; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php index 92980e3de6c..57f0b9a3a20 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php @@ -20,6 +20,7 @@ use function preg_split; use function reset; use function str_replace; +use function stripos; use function strlen; use function strpos; use function strtolower; diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index ef1be0e48bb..d6701770e36 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -14,7 +14,7 @@ use function filemtime; use function md5; use function strlen; -use function substr; +use function strpos; /** * @internal diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index a197250cf91..9ea23e96c57 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -29,6 +29,7 @@ use function get_class; use function max; +use function strpos; use function substr; class SimpleNegatedAssertionReconciler extends Reconciler diff --git a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php index 7767681514b..cc92d043028 100644 --- a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php @@ -14,7 +14,7 @@ use function array_merge; use function array_shift; use function array_values; -use function substr; +use function strpos; class TemplateInferredTypeReplacer { diff --git a/src/Psalm/Internal/Type/TypeTokenizer.php b/src/Psalm/Internal/Type/TypeTokenizer.php index 0882000b3ca..204361bf8f2 100644 --- a/src/Psalm/Internal/Type/TypeTokenizer.php +++ b/src/Psalm/Internal/Type/TypeTokenizer.php @@ -4,7 +4,6 @@ use Psalm\Aliases; use Psalm\Exception\TypeParseTreeException; -use function array_push; use function array_splice; use function array_unshift; use function count; diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index dfc41e3a9f5..88d9a286ce0 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -56,7 +56,6 @@ use function is_numeric; use function strpos; use function strtolower; -use function substr; abstract class Atomic implements TypeNode { diff --git a/src/Psalm/Type/Atomic/TCallableArray.php b/src/Psalm/Type/Atomic/TCallableArray.php index 5caffc5954c..6edaa611ce5 100644 --- a/src/Psalm/Type/Atomic/TCallableArray.php +++ b/src/Psalm/Type/Atomic/TCallableArray.php @@ -10,5 +10,4 @@ class TCallableArray extends TNonEmptyArray * @var string */ public $value = 'callable-array'; - } diff --git a/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php b/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php index c64dec91c44..4af9887df04 100644 --- a/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php +++ b/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php @@ -60,5 +60,4 @@ public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_ { return false; } - } diff --git a/src/Psalm/Type/Atomic/TTemplateParamClass.php b/src/Psalm/Type/Atomic/TTemplateParamClass.php index 3464dfe6b4c..9e50ccebade 100644 --- a/src/Psalm/Type/Atomic/TTemplateParamClass.php +++ b/src/Psalm/Type/Atomic/TTemplateParamClass.php @@ -61,5 +61,4 @@ public function toNamespacedString( ): string { return $this->param_name . '::class'; } - } diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index deccebec9b7..1f19e8f0bc9 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -26,7 +26,6 @@ use function reset; use function sort; use function strpos; -use function strval; class Union implements TypeNode {