From 53c0a4e63a596f6f3d7bf8aebfdf356ae95f96ba Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 4 Oct 2021 00:03:06 +0200 Subject: [PATCH 1/2] cleanup --- src/Psalm/Codebase.php | 2 +- src/Psalm/Config/IssueHandler.php | 7 +------ .../Analyzer/FunctionLike/ReturnTypeAnalyzer.php | 2 +- .../Analyzer/Statements/Block/TryAnalyzer.php | 5 +---- .../Call/FunctionCallReturnTypeFetcher.php | 2 +- .../Call/Method/MissingMethodCallHandler.php | 2 +- src/Psalm/Internal/Clause.php | 12 ++---------- src/Psalm/Internal/Cli/LanguageServer.php | 5 +---- src/Psalm/Internal/Cli/Psalm.php | 7 ++----- src/Psalm/Internal/Cli/Psalter.php | 7 ++----- src/Psalm/Internal/Cli/Refactor.php | 5 +---- src/Psalm/Internal/Codebase/Reflection.php | 2 +- src/Psalm/Internal/Diff/ClassStatementsDiffer.php | 13 +++---------- src/Psalm/Internal/Diff/FileStatementsDiffer.php | 10 ++-------- .../Internal/Diff/NamespaceStatementsDiffer.php | 10 ++-------- .../Internal/PhpVisitor/NodeCounterVisitor.php | 5 +---- .../Internal/PhpVisitor/OffsetShifterVisitor.php | 5 +---- .../Internal/PhpVisitor/PartialParserVisitor.php | 4 +--- src/Psalm/Internal/PhpVisitor/TraitFinder.php | 7 +------ src/Psalm/Internal/Provider/StatementsProvider.php | 14 ++------------ src/Psalm/Internal/Scanner/DocblockParser.php | 2 +- src/Psalm/Storage/ClassConstantStorage.php | 2 +- src/Psalm/Storage/PropertyStorage.php | 2 +- src/functions.php | 4 +--- 24 files changed, 32 insertions(+), 104 deletions(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 894ea7eb3..ca1649067 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -1399,7 +1399,7 @@ class Codebase if ($offset - $end_pos === 1) { $candidate_gap = substr($file_contents, $end_pos, 1); - if ($candidate_gap == '[') { + if ($candidate_gap === '[') { $gap = $candidate_gap; $recent_type = $possible_type; diff --git a/src/Psalm/Config/IssueHandler.php b/src/Psalm/Config/IssueHandler.php index 21e278e40..68f4921d7 100644 --- a/src/Psalm/Config/IssueHandler.php +++ b/src/Psalm/Config/IssueHandler.php @@ -138,12 +138,7 @@ class IssueHandler { return array_filter( array_map( - /** - * @param string $file_name - * - * @return string - */ - function ($file_name) { + function (string $file_name): string { return substr($file_name, 0, -4); }, scandir(dirname(__DIR__) . '/Issue', SCANDIR_SORT_NONE) diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index eb0d8e49a..707452496 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -393,7 +393,7 @@ class ReturnTypeAnalyzer $parent_class, true, true, - $function_like_storage instanceof MethodStorage && $function_like_storage->final + ($function_like_storage instanceof MethodStorage && $function_like_storage->final) || ($classlike_storage && $classlike_storage->final) ); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php index a444bf3c8..29b1978be 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -281,10 +281,7 @@ class TryAnalyzer $catch_context->vars_in_scope[$catch_var_id] = new Union( array_map( - /** - * @param string $fq_catch_class - */ - function ($fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject { + function (string $fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject { $catch_class_type = new TNamedObject($fq_catch_class); if (version_compare(PHP_VERSION, '7.0.0dev', '>=') diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php index 113bf5ff6..80ff7d3a4 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php @@ -713,7 +713,7 @@ class FunctionCallReturnTypeFetcher $next = $pattern[$i + 1] ?? null; if ($current === '\\') { - if ($next == null + if ($next === null || $next === 'x' || $next === 'u' ) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MissingMethodCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MissingMethodCallHandler.php index cc39b4fca..82f74b705 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MissingMethodCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MissingMethodCallHandler.php @@ -126,7 +126,7 @@ class MissingMethodCallHandler return null; } - } elseif ($all_intersection_return_type == null) { + } elseif ($all_intersection_return_type === null) { ArgumentsAnalyzer::analyze( $statements_analyzer, $stmt->args, diff --git a/src/Psalm/Internal/Clause.php b/src/Psalm/Internal/Clause.php index 61eadf0a1..d6b5f1174 100644 --- a/src/Psalm/Internal/Clause.php +++ b/src/Psalm/Internal/Clause.php @@ -131,23 +131,15 @@ class Clause { $clause_strings = array_map( /** - * @param string $var_id * @param non-empty-list $values - * - * @return string */ - function ($var_id, $values): string { + function (string $var_id, array $values): string { if ($var_id[0] === '*') { $var_id = ''; } $var_id_clauses = array_map( - /** - * @param string $value - * - * @return string - */ - function ($value) use ($var_id): string { + function (string $value) use ($var_id): string { if ($value === 'falsy') { return '!' . $var_id; } diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index b7d2d58d1..70f134b98 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -82,10 +82,7 @@ final class LanguageServer } array_map( - /** - * @param string $arg - */ - function ($arg) use ($valid_long_options): void { + function (string $arg) use ($valid_long_options): void { if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index 7e80ad592..61637edf1 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -416,10 +416,7 @@ final class Psalm private static function validateCliArguments(array $args): void { array_map( - /** - * @param string $arg - */ - function ($arg): void { + function (string $arg): void { if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); @@ -456,7 +453,7 @@ final class Psalm /** * @param array> $options */ - private static function setMemoryLimit($options): void + private static function setMemoryLimit(array $options): void { if (!array_key_exists('use-ini-defaults', $options)) { ini_set('display_errors', 'stderr'); diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index 40bd193f3..8064767c1 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -427,13 +427,10 @@ HELP; } /** @param array $args */ - private static function validateCliArguments($args): void + private static function validateCliArguments(array $args): void { array_map( - /** - * @param string $arg - */ - function ($arg): void { + function (string $arg): void { if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); diff --git a/src/Psalm/Internal/Cli/Refactor.php b/src/Psalm/Internal/Cli/Refactor.php index b63ef6d10..6edda8fbb 100644 --- a/src/Psalm/Internal/Cli/Refactor.php +++ b/src/Psalm/Internal/Cli/Refactor.php @@ -71,10 +71,7 @@ final class Refactor $options = getopt(implode('', $valid_short_options), $valid_long_options); array_map( - /** - * @param string $arg - */ - function ($arg) use ($valid_long_options): void { + function (string $arg) use ($valid_long_options): void { if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); diff --git a/src/Psalm/Internal/Codebase/Reflection.php b/src/Psalm/Internal/Codebase/Reflection.php index 02d44c779..3b8e38157 100644 --- a/src/Psalm/Internal/Codebase/Reflection.php +++ b/src/Psalm/Internal/Codebase/Reflection.php @@ -260,7 +260,7 @@ class Reflection $storage->is_static = $method->isStatic(); $storage->abstract = $method->isAbstract(); $storage->mutation_free = $storage->external_mutation_free - = $method_name_lc === '__construct' && $fq_class_name_lc === 'datetimezone'; + = ($method_name_lc === '__construct' && $fq_class_name_lc === 'datetimezone'); $class_storage->declaring_method_ids[$method_name_lc] = new \Psalm\Internal\MethodIdentifier( $declaring_class->name, diff --git a/src/Psalm/Internal/Diff/ClassStatementsDiffer.php b/src/Psalm/Internal/Diff/ClassStatementsDiffer.php index 97d2aa528..8b9a76416 100644 --- a/src/Psalm/Internal/Diff/ClassStatementsDiffer.php +++ b/src/Psalm/Internal/Diff/ClassStatementsDiffer.php @@ -34,19 +34,12 @@ class ClassStatementsDiffer extends AstDiffer $diff_map = []; [$trace, $x, $y, $bc] = self::calculateTrace( - /** - * @param string $a_code - * @param string $b_code - * @param bool $body_change - * - * @return bool - */ function ( PhpParser\Node\Stmt $a, PhpParser\Node\Stmt $b, - $a_code, - $b_code, - &$body_change = false + string $a_code, + string $b_code, + bool &$body_change = false ) use (&$diff_map): bool { if (get_class($a) !== get_class($b)) { return false; diff --git a/src/Psalm/Internal/Diff/FileStatementsDiffer.php b/src/Psalm/Internal/Diff/FileStatementsDiffer.php index babac18b9..522b69ff3 100644 --- a/src/Psalm/Internal/Diff/FileStatementsDiffer.php +++ b/src/Psalm/Internal/Diff/FileStatementsDiffer.php @@ -29,17 +29,11 @@ class FileStatementsDiffer extends AstDiffer public static function diff(array $a, array $b, string $a_code, string $b_code): array { [$trace, $x, $y, $bc] = self::calculateTrace( - /** - * @param string $a_code - * @param string $b_code - * - * @return bool - */ function ( PhpParser\Node\Stmt $a, PhpParser\Node\Stmt $b, - $a_code, - $b_code, + string $a_code, + string $b_code, bool &$body_change = false ): bool { if (get_class($a) !== get_class($b)) { diff --git a/src/Psalm/Internal/Diff/NamespaceStatementsDiffer.php b/src/Psalm/Internal/Diff/NamespaceStatementsDiffer.php index a81827ebc..7970426f0 100644 --- a/src/Psalm/Internal/Diff/NamespaceStatementsDiffer.php +++ b/src/Psalm/Internal/Diff/NamespaceStatementsDiffer.php @@ -29,17 +29,11 @@ class NamespaceStatementsDiffer extends AstDiffer public static function diff(string $name, array $a, array $b, string $a_code, string $b_code): array { [$trace, $x, $y, $bc] = self::calculateTrace( - /** - * @param string $a_code - * @param string $b_code - * - * @return bool - */ function ( PhpParser\Node\Stmt $a, PhpParser\Node\Stmt $b, - $a_code, - $b_code, + string $a_code, + string $b_code, bool &$body_change = false ): bool { if (get_class($a) !== get_class($b)) { diff --git a/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php b/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php index 91aa4a870..a2146327b 100644 --- a/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/NodeCounterVisitor.php @@ -11,10 +11,7 @@ class NodeCounterVisitor extends PhpParser\NodeVisitorAbstract /** @var int */ public $count = 0; - /** - * @return null|int - */ - public function enterNode(PhpParser\Node $node) + public function enterNode(PhpParser\Node $node): ?int { $this->count++; diff --git a/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php b/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php index 499b5f3e1..5bb19da3a 100644 --- a/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/OffsetShifterVisitor.php @@ -27,10 +27,7 @@ class OffsetShifterVisitor extends PhpParser\NodeVisitorAbstract $this->extra_offsets = $extra_offsets; } - /** - * @return null|int - */ - public function enterNode(PhpParser\Node $node) + public function enterNode(PhpParser\Node $node): ?int { /** @var array{startFilePos: int, endFilePos: int, startLine: int} */ $attrs = $node->getAttributes(); diff --git a/src/Psalm/Internal/PhpVisitor/PartialParserVisitor.php b/src/Psalm/Internal/PhpVisitor/PartialParserVisitor.php index 04ccce757..bdcb37afc 100644 --- a/src/Psalm/Internal/PhpVisitor/PartialParserVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/PartialParserVisitor.php @@ -60,11 +60,9 @@ class PartialParserVisitor extends PhpParser\NodeVisitorAbstract } /** - * @param bool $traverseChildren - * * @return null|int|PhpParser\Node */ - public function enterNode(PhpParser\Node $node, &$traverseChildren = true) + public function enterNode(PhpParser\Node $node, bool &$traverseChildren = true) { /** @var array{startFilePos: int, endFilePos: int, startLine: int} */ $attrs = $node->getAttributes(); diff --git a/src/Psalm/Internal/PhpVisitor/TraitFinder.php b/src/Psalm/Internal/PhpVisitor/TraitFinder.php index ab4e6fa7d..e13003408 100644 --- a/src/Psalm/Internal/PhpVisitor/TraitFinder.php +++ b/src/Psalm/Internal/PhpVisitor/TraitFinder.php @@ -21,12 +21,7 @@ class TraitFinder extends PhpParser\NodeVisitorAbstract $this->fq_trait_name = $fq_trait_name; } - /** - * @param bool $traverseChildren - * - * @return int|null - */ - public function enterNode(PhpParser\Node $node, &$traverseChildren = true) + public function enterNode(PhpParser\Node $node, bool &$traverseChildren = true): ?int { if ($node instanceof PhpParser\Node\Stmt\Trait_) { /** @var ?string */ diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index d6701770e..60035ada8 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -200,24 +200,14 @@ class StatementsProvider ); $unchanged_members = array_map( - /** - * @param int $_ - * - * @return bool - */ - function ($_): bool { + function (int $_): bool { return true; }, array_flip($unchanged_members) ); $unchanged_signature_members = array_map( - /** - * @param int $_ - * - * @return bool - */ - function ($_): bool { + function (int $_): bool { return true; }, array_flip($unchanged_signature_members) diff --git a/src/Psalm/Internal/Scanner/DocblockParser.php b/src/Psalm/Internal/Scanner/DocblockParser.php index aa9a11c30..7e464d007 100644 --- a/src/Psalm/Internal/Scanner/DocblockParser.php +++ b/src/Psalm/Internal/Scanner/DocblockParser.php @@ -81,7 +81,7 @@ class DocblockParser if (preg_match('/^[ \t]*\*?\s*@([\w\-\\\:]+)[\t ]*(.*)$/sm', $line, $matches, PREG_OFFSET_CAPTURE)) { /** @var array $matches */ - [$_, $type_info, $data_info] = $matches; + [, $type_info, $data_info] = $matches; [$type] = $type_info; [$data, $data_offset] = $data_info; diff --git a/src/Psalm/Storage/ClassConstantStorage.php b/src/Psalm/Storage/ClassConstantStorage.php index ac752dc10..cf1effd30 100644 --- a/src/Psalm/Storage/ClassConstantStorage.php +++ b/src/Psalm/Storage/ClassConstantStorage.php @@ -15,7 +15,7 @@ class ClassConstantStorage /** * @var ClassLikeAnalyzer::VISIBILITY_* */ - public $visibility = 1; + public $visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC; /** * @var ?CodeLocation diff --git a/src/Psalm/Storage/PropertyStorage.php b/src/Psalm/Storage/PropertyStorage.php index 2452f2b0c..9fdd06fb4 100644 --- a/src/Psalm/Storage/PropertyStorage.php +++ b/src/Psalm/Storage/PropertyStorage.php @@ -17,7 +17,7 @@ class PropertyStorage /** * @var ClassLikeAnalyzer::VISIBILITY_* */ - public $visibility = 1; + public $visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC; /** * @var CodeLocation|null diff --git a/src/functions.php b/src/functions.php index fe5a87712..4145e43b3 100644 --- a/src/functions.php +++ b/src/functions.php @@ -4,11 +4,9 @@ namespace Psalm; use Webmozart\PathUtil\Path; /** - * @param string $path - * * @deprecated Use {@see Webmozart\PathUtil\Path::isAbsolute}. No longer used by Psalm, going to be removed in Psalm 5 */ -function isAbsolutePath($path): bool +function isAbsolutePath(string $path): bool { return Path::isAbsolute($path); } From 430fd619eca3e1a206b2d7bef36eea88998dbe74 Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 4 Oct 2021 00:23:53 +0200 Subject: [PATCH 2/2] cleanup --- src/Psalm/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 7f58038ed..35abdc529 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -1257,7 +1257,7 @@ class Config self::requirePath($plugin_class_path); } else { - if (!class_exists($plugin_class_name, true)) { + if (!class_exists($plugin_class_name)) { throw new \UnexpectedValueException($plugin_class_name . ' is not a known class'); } } @@ -2240,7 +2240,7 @@ class Config public function addUniversalObjectCrate(string $class): void { - if (!class_exists($class, true)) { + if (!class_exists($class)) { throw new \UnexpectedValueException($class . ' is not a known class'); } $this->universal_object_crates[] = $class;