1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 02:27:59 +01:00
This commit is contained in:
Daniil Gentili 2023-10-19 20:41:14 +02:00
parent a8ccc92da4
commit 34b427286a
13 changed files with 26 additions and 28 deletions

View File

@ -1386,10 +1386,11 @@ final class AssertionFinder
/** /**
* @param Identical|Equal|NotIdentical|NotEqual $conditional * @param Identical|Equal|NotIdentical|NotEqual $conditional
* @return false|int
*/ */
private static function hasGetTypeCheck( private static function hasGetTypeCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
): false|int { ): bool|int {
if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name && $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->getFirst()) === 'gettype' && strtolower($conditional->right->name->getFirst()) === 'gettype'
@ -1413,10 +1414,11 @@ final class AssertionFinder
/** /**
* @param Identical|Equal|NotIdentical|NotEqual $conditional * @param Identical|Equal|NotIdentical|NotEqual $conditional
* @return false|int
*/ */
private static function hasGetDebugTypeCheck( private static function hasGetDebugTypeCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
): false|int { ): bool|int {
if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall if ($conditional->right instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->right->name instanceof PhpParser\Node\Name && $conditional->right->name instanceof PhpParser\Node\Name
&& strtolower($conditional->right->name->getFirst()) === 'get_debug_type' && strtolower($conditional->right->name->getFirst()) === 'get_debug_type'
@ -1442,11 +1444,12 @@ final class AssertionFinder
/** /**
* @param Identical|Equal|NotIdentical|NotEqual $conditional * @param Identical|Equal|NotIdentical|NotEqual $conditional
* @return false|int
*/ */
private static function hasGetClassCheck( private static function hasGetClassCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
FileSource $source, FileSource $source,
): false|int { ): bool|int {
if (!$source instanceof StatementsAnalyzer) { if (!$source instanceof StatementsAnalyzer) {
return false; return false;
} }
@ -1534,11 +1537,12 @@ final class AssertionFinder
/** /**
* @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional * @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional
* @return false|int
*/ */
private static function hasNonEmptyCountEqualityCheck( private static function hasNonEmptyCountEqualityCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
?int &$min_count, ?int &$min_count,
): false|int { ): bool|int {
if ($conditional->left instanceof PhpParser\Node\Expr\FuncCall if ($conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name && $conditional->left->name instanceof PhpParser\Node\Name
&& in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']) && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof'])
@ -1575,11 +1579,12 @@ final class AssertionFinder
/** /**
* @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional * @param Greater|GreaterOrEqual|Smaller|SmallerOrEqual $conditional
* @return false|int
*/ */
private static function hasLessThanCountEqualityCheck( private static function hasLessThanCountEqualityCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
?int &$max_count, ?int &$max_count,
): false|int { ): bool|int {
$left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name && $conditional->left->name instanceof PhpParser\Node\Name
&& in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']) && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof'])
@ -1623,11 +1628,12 @@ final class AssertionFinder
/** /**
* @param Equal|Identical|NotEqual|NotIdentical $conditional * @param Equal|Identical|NotEqual|NotIdentical $conditional
* @return false|int
*/ */
private static function hasCountEqualityCheck( private static function hasCountEqualityCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
?int &$count, ?int &$count,
): false|int { ): bool|int {
$left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name && $conditional->left->name instanceof PhpParser\Node\Name
&& in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']) && 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 * @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional
* @return false|int
*/ */
private static function hasSuperiorNumberCheck( private static function hasSuperiorNumberCheck(
FileSource $source, FileSource $source,
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
?int &$literal_value_comparison, ?int &$literal_value_comparison,
): false|int { ): bool|int {
$right_assignment = false; $right_assignment = false;
$value_right = null; $value_right = null;
if ($source instanceof StatementsAnalyzer if ($source instanceof StatementsAnalyzer
@ -1714,12 +1721,13 @@ final class AssertionFinder
/** /**
* @param PhpParser\Node\Expr\BinaryOp\Smaller|PhpParser\Node\Expr\BinaryOp\SmallerOrEqual $conditional * @param PhpParser\Node\Expr\BinaryOp\Smaller|PhpParser\Node\Expr\BinaryOp\SmallerOrEqual $conditional
* @return false|int
*/ */
private static function hasInferiorNumberCheck( private static function hasInferiorNumberCheck(
FileSource $source, FileSource $source,
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
?int &$literal_value_comparison, ?int &$literal_value_comparison,
): false|int { ): bool|int {
$right_assignment = false; $right_assignment = false;
$value_right = null; $value_right = null;
if ($source instanceof StatementsAnalyzer if ($source instanceof StatementsAnalyzer
@ -1773,10 +1781,11 @@ final class AssertionFinder
/** /**
* @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional * @param PhpParser\Node\Expr\BinaryOp\Greater|PhpParser\Node\Expr\BinaryOp\GreaterOrEqual $conditional
* @return false|int
*/ */
private static function hasReconcilableNonEmptyCountEqualityCheck( private static function hasReconcilableNonEmptyCountEqualityCheck(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
): false|int { ): bool|int {
$left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall $left_count = $conditional->left instanceof PhpParser\Node\Expr\FuncCall
&& $conditional->left->name instanceof PhpParser\Node\Name && $conditional->left->name instanceof PhpParser\Node\Name
&& in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']); && in_array(strtolower($conditional->left->name->getFirst()), ['count', 'sizeof']);
@ -1794,11 +1803,12 @@ final class AssertionFinder
/** /**
* @param Identical|Equal|NotIdentical|NotEqual $conditional * @param Identical|Equal|NotIdentical|NotEqual $conditional
* @return false|int
*/ */
private static function hasTypedValueComparison( private static function hasTypedValueComparison(
PhpParser\Node\Expr\BinaryOp $conditional, PhpParser\Node\Expr\BinaryOp $conditional,
FileSource $source, FileSource $source,
): false|int { ): bool|int {
if (!$source instanceof StatementsAnalyzer) { if (!$source instanceof StatementsAnalyzer) {
return false; return false;
} }

View File

@ -114,7 +114,7 @@ final class AssignmentAnalyzer
?PhpParser\Comment\Doc $doc_comment, ?PhpParser\Comment\Doc $doc_comment,
array $not_ignored_docblock_var_ids = [], array $not_ignored_docblock_var_ids = [],
?PhpParser\Node\Expr $assign_expr = null, ?PhpParser\Node\Expr $assign_expr = null,
): false|Union { ): ?Union {
$var_id = ExpressionIdentifier::getVarId( $var_id = ExpressionIdentifier::getVarId(
$assign_var, $assign_var,
$statements_analyzer->getFQCLN(), $statements_analyzer->getFQCLN(),
@ -680,7 +680,7 @@ final class AssignmentAnalyzer
$assign_value, $assign_value,
$assign_value_type, $assign_value_type,
$context, $context,
) === false) { ) === null) {
return false; return false;
} }
} }

View File

@ -536,7 +536,7 @@ final class ExpressionAnalyzer
!$from_stmt ? $stmt : null, !$from_stmt ? $stmt : null,
); );
if ($assignment_type === false) { if ($assignment_type === null) {
return false; return false;
} }

View File

@ -24,8 +24,6 @@ use function reset;
use function serialize; use function serialize;
use function substr; use function substr;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal
* @psalm-immutable * @psalm-immutable

View File

@ -1118,7 +1118,7 @@ final class Psalm
} }
/** @return false|'always'|'auto' */ /** @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; $find_unused_code = false;
if (isset($options['find-dead-code'])) { if (isset($options['find-dead-code'])) {

View File

@ -20,8 +20,6 @@ use function preg_replace;
use function strlen; use function strlen;
use function strtolower; use function strtolower;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal
*/ */

View File

@ -46,8 +46,6 @@ use function spl_object_id;
use function strpos; use function strpos;
use function strtolower; use function strtolower;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal
*/ */

View File

@ -21,7 +21,6 @@ use function mkdir;
use function strtolower; use function strtolower;
use const DIRECTORY_SEPARATOR; use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal

View File

@ -20,7 +20,6 @@ use function mkdir;
use function strtolower; use function strtolower;
use const DIRECTORY_SEPARATOR; use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal

View File

@ -32,7 +32,6 @@ use function touch;
use const DIRECTORY_SEPARATOR; use const DIRECTORY_SEPARATOR;
use const JSON_THROW_ON_ERROR; use const JSON_THROW_ON_ERROR;
use const LOCK_EX; use const LOCK_EX;
use const PHP_VERSION_ID;
use const SCANDIR_SORT_NONE; use const SCANDIR_SORT_NONE;
/** /**

View File

@ -14,7 +14,6 @@ use function mkdir;
use function touch; use function touch;
use const DIRECTORY_SEPARATOR; use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;
/** /**
* Used to determine which files reference other files, necessary for using the --diff * Used to determine which files reference other files, necessary for using the --diff

View File

@ -37,8 +37,6 @@ use function str_starts_with;
use function strlen; use function strlen;
use function strpos; use function strpos;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal
*/ */

View File

@ -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); $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) { 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(); return $this->statements_analyzer->node_data->getType($arg->value) ?? Type::getMixed();