From 34b427286a28d0de0e5514de9d9756bcfa7e391b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 19 Oct 2023 20:41:14 +0200 Subject: [PATCH] Fixup --- .../Statements/Expression/AssertionFinder.php | 30 ++++++++++++------- .../Expression/AssignmentAnalyzer.php | 4 +-- .../Statements/ExpressionAnalyzer.php | 2 +- src/Psalm/Internal/Clause.php | 2 -- src/Psalm/Internal/Cli/Psalm.php | 2 +- src/Psalm/Internal/Fork/PsalmRestarter.php | 2 -- .../Internal/PhpVisitor/ReflectorVisitor.php | 2 -- .../ClassLikeStorageCacheProvider.php | 1 - .../Provider/FileStorageCacheProvider.php | 1 - .../Internal/Provider/ParserCacheProvider.php | 1 - .../Provider/ProjectCacheProvider.php | 1 - .../Internal/Provider/StatementsProvider.php | 2 -- src/Psalm/Plugin/ArgTypeInferer.php | 4 +-- 13 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 79e102de0..9afa824be 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -1386,10 +1386,11 @@ final class AssertionFinder /** * @param Identical|Equal|NotIdentical|NotEqual $conditional + * @return false|int */ private static function hasGetTypeCheck( PhpParser\Node\Expr\BinaryOp $conditional, - ): false|int { + ): bool|int { if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall && $conditional->right->name instanceof PhpParser\Node\Name && strtolower($conditional->right->name->getFirst()) === 'gettype' @@ -1413,10 +1414,11 @@ final class AssertionFinder /** * @param Identical|Equal|NotIdentical|NotEqual $conditional + * @return false|int */ private static function hasGetDebugTypeCheck( PhpParser\Node\Expr\BinaryOp $conditional, - ): false|int { + ): bool|int { if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall && $conditional->right->name instanceof PhpParser\Node\Name && strtolower($conditional->right->name->getFirst()) === 'get_debug_type' @@ -1442,11 +1444,12 @@ final class AssertionFinder /** * @param Identical|Equal|NotIdentical|NotEqual $conditional + * @return false|int */ private static function hasGetClassCheck( PhpParser\Node\Expr\BinaryOp $conditional, FileSource $source, - ): false|int { + ): bool|int { if (!$source instanceof StatementsAnalyzer) { return false; } @@ -1534,11 +1537,12 @@ final class AssertionFinder /** * @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional + * @return false|int */ private static function hasNonEmptyCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ?int &$min_count, - ): false|int { + ): bool|int { if ($conditional->left instanceof PhpParser\Node\Expr\FuncCall && $conditional->left->name instanceof PhpParser\Node\Name && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']) @@ -1575,11 +1579,12 @@ final class AssertionFinder /** * @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional + * @return false|int */ private static function hasLessThanCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ?int &$max_count, - ): false|int { + ): bool|int { $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall && $conditional->left->name instanceof PhpParser\Node\Name && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']) @@ -1623,11 +1628,12 @@ final class AssertionFinder /** * @param Equal|Identical|NotEqual|NotIdentical $conditional + * @return false|int */ private static function hasCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, ?int &$count, - ): false|int { + ): bool|int { $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall && $conditional->left->name instanceof PhpParser\Node\Name && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']) @@ -1655,12 +1661,13 @@ final class AssertionFinder /** * @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional + * @return false|int */ private static function hasSuperiorNumberCheck( FileSource $source, PhpParser\Node\Expr\BinaryOp $conditional, ?int &$literal_value_comparison, - ): false|int { + ): bool|int { $right_assignment = false; $value_right = null; if ($source instanceof StatementsAnalyzer @@ -1714,12 +1721,13 @@ final class AssertionFinder /** * @param PhpParser\Node\Expr\BinaryOp\Smaller|PhpParser\Node\Expr\BinaryOp\SmallerOrEqual $conditional + * @return false|int */ private static function hasInferiorNumberCheck( FileSource $source, PhpParser\Node\Expr\BinaryOp $conditional, ?int &$literal_value_comparison, - ): false|int { + ): bool|int { $right_assignment = false; $value_right = null; if ($source instanceof StatementsAnalyzer @@ -1773,10 +1781,11 @@ final class AssertionFinder /** * @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional + * @return false|int */ private static function hasReconcilableNonEmptyCountEqualityCheck( PhpParser\Node\Expr\BinaryOp $conditional, - ): false|int { + ): bool|int { $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall && $conditional->left->name instanceof PhpParser\Node\Name && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']); @@ -1794,11 +1803,12 @@ final class AssertionFinder /** * @param Identical|Equal|NotIdentical|NotEqual $conditional + * @return false|int */ private static function hasTypedValueComparison( PhpParser\Node\Expr\BinaryOp $conditional, FileSource $source, - ): false|int { + ): bool|int { if (!$source instanceof StatementsAnalyzer) { return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index aea4fba53..baa0c6e72 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -114,7 +114,7 @@ final class AssignmentAnalyzer ?PhpParser\Comment\Doc $doc_comment, array $not_ignored_docblock_var_ids = [], ?PhpParser\Node\Expr $assign_expr = null, - ): false|Union { + ): ?Union { $var_id = ExpressionIdentifier::getVarId( $assign_var, $statements_analyzer->getFQCLN(), @@ -680,7 +680,7 @@ final class AssignmentAnalyzer $assign_value, $assign_value_type, $context, - ) === false) { + ) === null) { return false; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php index 3fdf106e2..7b167153e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php @@ -536,7 +536,7 @@ final class ExpressionAnalyzer !$from_stmt ? $stmt : null, ); - if ($assignment_type === false) { + if ($assignment_type === null) { return false; } diff --git a/src/Psalm/Internal/Clause.php b/src/Psalm/Internal/Clause.php index 797fb5d3f..31c8e2804 100644 --- a/src/Psalm/Internal/Clause.php +++ b/src/Psalm/Internal/Clause.php @@ -24,8 +24,6 @@ use function reset; use function serialize; use function substr; -use const PHP_VERSION_ID; - /** * @internal * @psalm-immutable diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index 88a8fa895..5aee0ced1 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -1118,7 +1118,7 @@ final class Psalm } /** @return false|'always'|'auto' */ - private static function shouldFindUnusedCode(array $options, Config $config): false|string + private static function shouldFindUnusedCode(array $options, Config $config): bool|string { $find_unused_code = false; if (isset($options['find-dead-code'])) { diff --git a/src/Psalm/Internal/Fork/PsalmRestarter.php b/src/Psalm/Internal/Fork/PsalmRestarter.php index 8c1d6bfa5..69b6089cf 100644 --- a/src/Psalm/Internal/Fork/PsalmRestarter.php +++ b/src/Psalm/Internal/Fork/PsalmRestarter.php @@ -20,8 +20,6 @@ use function preg_replace; use function strlen; use function strtolower; -use const PHP_VERSION_ID; - /** * @internal */ diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 4497963b4..bc911d8cd 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -46,8 +46,6 @@ use function spl_object_id; use function strpos; use function strtolower; -use const PHP_VERSION_ID; - /** * @internal */ diff --git a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php index 75863abd8..73975ea21 100644 --- a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php @@ -21,7 +21,6 @@ use function mkdir; use function strtolower; use const DIRECTORY_SEPARATOR; -use const PHP_VERSION_ID; /** * @internal diff --git a/src/Psalm/Internal/Provider/FileStorageCacheProvider.php b/src/Psalm/Internal/Provider/FileStorageCacheProvider.php index e766769d7..ee02fadad 100644 --- a/src/Psalm/Internal/Provider/FileStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileStorageCacheProvider.php @@ -20,7 +20,6 @@ use function mkdir; use function strtolower; use const DIRECTORY_SEPARATOR; -use const PHP_VERSION_ID; /** * @internal diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index 2125c190f..0c6bba2af 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -32,7 +32,6 @@ use function touch; use const DIRECTORY_SEPARATOR; use const JSON_THROW_ON_ERROR; use const LOCK_EX; -use const PHP_VERSION_ID; use const SCANDIR_SORT_NONE; /** diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index 0a162b94f..6200430f8 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -14,7 +14,6 @@ use function mkdir; use function touch; use const DIRECTORY_SEPARATOR; -use const PHP_VERSION_ID; /** * Used to determine which files reference other files, necessary for using the --diff diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index 471632e13..b5bdbef8a 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -37,8 +37,6 @@ use function str_starts_with; use function strlen; use function strpos; -use const PHP_VERSION_ID; - /** * @internal */ diff --git a/src/Psalm/Plugin/ArgTypeInferer.php b/src/Psalm/Plugin/ArgTypeInferer.php index cb70f91a9..109769c80 100644 --- a/src/Psalm/Plugin/ArgTypeInferer.php +++ b/src/Psalm/Plugin/ArgTypeInferer.php @@ -22,7 +22,7 @@ final class ArgTypeInferer ) { } - public function infer(PhpParser\Node\Arg $arg): false|Union + public function infer(PhpParser\Node\Arg $arg): null|Union { $already_inferred_type = $this->statements_analyzer->node_data->getType($arg->value); @@ -31,7 +31,7 @@ final class ArgTypeInferer } if (ExpressionAnalyzer::analyze($this->statements_analyzer, $arg->value, $this->context) === false) { - return false; + return null; } return $this->statements_analyzer->node_data->getType($arg->value) ?? Type::getMixed();