mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Replace some LNumber usages
This commit is contained in:
parent
d71e7af46a
commit
8013b0eea2
@ -7,7 +7,7 @@
|
||||
|
||||
- [BC] The only optional boolean parameter of `TKeyedArray::getGenericArrayType` was removed, and was replaced with a string parameter with a different meaning.
|
||||
|
||||
- [BC] The `TDependentListKey` type was removed, replacing it with an optional property of the `TIntRange` type.
|
||||
- [BC] The `TDependentListKey` type was removed and replaced with an optional property of the `TIntRange` type.
|
||||
|
||||
# Upgrading from Psalm 4 to Psalm 5
|
||||
## Changed
|
||||
|
@ -106,14 +106,15 @@ class ForAnalyzer
|
||||
if (count($stmt->init) === 1
|
||||
&& count($stmt->cond) === 1
|
||||
&& $cond instanceof PhpParser\Node\Expr\BinaryOp
|
||||
&& $cond->right instanceof PhpParser\Node\Scalar\LNumber
|
||||
&& ($cond_value = $statements_analyzer->node_data->getType($cond->right))
|
||||
&& ($cond_value->isSingleIntLiteral() || $cond_value->isSingleStringLiteral())
|
||||
&& $cond->left instanceof PhpParser\Node\Expr\Variable
|
||||
&& is_string($cond->left->name)
|
||||
&& isset($init_var_types[$cond->left->name])
|
||||
&& $init_var_types[$cond->left->name]->isSingleIntLiteral()
|
||||
) {
|
||||
$init_value = $init_var_types[$cond->left->name]->getSingleIntLiteral()->value;
|
||||
$cond_value = $cond->right->value;
|
||||
$init_value = $init_var_types[$cond->left->name]->getSingleLiteral()->value;
|
||||
$cond_value = $cond_value->getSingleLiteral()->value;
|
||||
|
||||
if ($cond instanceof PhpParser\Node\Expr\BinaryOp\Smaller && $init_value < $cond_value) {
|
||||
$always_enters_loop = true;
|
||||
|
@ -27,7 +27,8 @@ class WhileAnalyzer
|
||||
Context $context
|
||||
): ?bool {
|
||||
$while_true = ($stmt->cond instanceof PhpParser\Node\Expr\ConstFetch && $stmt->cond->name->parts === ['true'])
|
||||
|| ($stmt->cond instanceof PhpParser\Node\Scalar\LNumber && $stmt->cond->value > 0);
|
||||
|| (($t = $statements_analyzer->node_data->getType($stmt->cond))
|
||||
&& $t->isAlwaysTruthy());
|
||||
|
||||
$pre_context = null;
|
||||
|
||||
|
@ -333,9 +333,18 @@ class IncludeAnalyzer
|
||||
if (isset($stmt->getArgs()[1])) {
|
||||
if ($stmt->getArgs()[1]->value instanceof PhpParser\Node\Scalar\LNumber) {
|
||||
$dir_level = $stmt->getArgs()[1]->value->value;
|
||||
} else {
|
||||
if ($statements_analyzer) {
|
||||
$t = $statements_analyzer->node_data->getType($stmt->getArgs()[1]->value);
|
||||
if ($t && $t->isSingleIntLiteral()) {
|
||||
$dir_level = $t->getSingleIntLiteral()->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$evaled_path = self::getPathTo(
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Psalm\Internal\Provider\ReturnTypeProvider;
|
||||
|
||||
use PhpParser;
|
||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||
use Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent;
|
||||
use Psalm\Plugin\EventHandler\FunctionReturnTypeProviderInterface;
|
||||
@ -54,15 +53,21 @@ class ArrayRandReturnTypeProvider implements FunctionReturnTypeProviderInterface
|
||||
$key_type = $first_arg_array->getGenericKeyType();
|
||||
}
|
||||
|
||||
if (!$second_arg
|
||||
|| ($second_arg instanceof PhpParser\Node\Scalar\LNumber && $second_arg->value === 1)
|
||||
if (!$second_arg) {
|
||||
return $key_type;
|
||||
}
|
||||
|
||||
$second_arg_type = $statements_source->node_data->getType($second_arg);
|
||||
if ($second_arg_type
|
||||
&& $second_arg_type->isSingleIntLiteral()
|
||||
&& $second_arg_type->getSingleIntLiteral()->value === 1
|
||||
) {
|
||||
return $key_type;
|
||||
}
|
||||
|
||||
$arr_type = Type::getList($key_type);
|
||||
|
||||
if ($second_arg instanceof PhpParser\Node\Scalar\LNumber) {
|
||||
if ($second_arg_type && $second_arg_type->isSingleIntLiteral()) {
|
||||
return $arr_type;
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,9 @@ class ExplodeReturnTypeProvider implements FunctionReturnTypeProviderInterface
|
||||
|
||||
$can_return_empty = isset($call_args[2])
|
||||
&& (
|
||||
!$call_args[2]->value instanceof PhpParser\Node\Scalar\LNumber
|
||||
|| $call_args[2]->value->value < 0
|
||||
!($third_arg_type = $statements_source->node_data->getType($call_args[2]->value))
|
||||
|| !$third_arg_type->isSingleIntLiteral()
|
||||
|| $third_arg_type->getSingleIntLiteral()->value < 0
|
||||
);
|
||||
|
||||
if ($call_args[0]->value instanceof PhpParser\Node\Scalar\String_) {
|
||||
|
Loading…
Reference in New Issue
Block a user