1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix errors in return types (#4189)

* FunctionLikeAnalyzer::verifyReturnType returns void

* ArrayFunctionArgumentsAnalyzer::checkArgumentsMatch returns void

* AssertionFinder::scrapeAssertions can't return null
This commit is contained in:
orklah 2020-09-16 23:35:55 +02:00 committed by Daniil Gentili
parent a71af5a5e5
commit 2c1ff808bb
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 30 additions and 58 deletions

View File

@ -1490,8 +1490,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
/**
* @param array<PhpParser\Node\Stmt> $function_stmts
*
* @return false|null
*/
public function verifyReturnType(
array $function_stmts,
@ -1501,7 +1499,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
?CodeLocation $return_type_location = null,
bool $did_explicitly_return = false,
bool $closure_inside_call = false
) {
): void {
ReturnTypeAnalyzer::verifyReturnType(
$this->function,
$function_stmts,

View File

@ -37,7 +37,7 @@ class AssertionFinder
/**
* Gets all the type assertions in a conditional
*
* @return array<string, non-empty-list<non-empty-list<string>>>|null
* @return array<string, non-empty-list<non-empty-list<string>>>
*/
public static function scrapeAssertions(
PhpParser\Node\Expr $conditional,
@ -47,7 +47,7 @@ class AssertionFinder
bool $inside_negation = false,
bool $cache = true,
bool $inside_conditional = true
) {
): array {
$if_types = [];
if ($conditional instanceof PhpParser\Node\Expr\Instanceof_) {
@ -195,10 +195,6 @@ class AssertionFinder
}
}
if ($expr_assertions === null) {
throw new \UnexpectedValueException('Assertions should be set');
}
if (count($expr_assertions) !== 1) {
return [];
}
@ -699,10 +695,6 @@ class AssertionFinder
}
}
if ($base_assertions === null) {
throw new \UnexpectedValueException('Assertions should be set');
}
$if_types = $base_assertions;
}
}
@ -820,10 +812,6 @@ class AssertionFinder
}
}
if ($base_assertions === null) {
throw new \UnexpectedValueException('Assertions should be set');
}
$notif_types = $base_assertions;
if (count($notif_types) === 1) {
@ -1338,10 +1326,6 @@ class AssertionFinder
}
}
if ($base_assertions === null) {
throw new \UnexpectedValueException('Assertions should be set');
}
$notif_types = $base_assertions;
if (count($notif_types) === 1) {
@ -1448,10 +1432,6 @@ class AssertionFinder
}
}
if ($base_assertions === null) {
throw new \UnexpectedValueException('Assertions should be set');
}
$notif_types = $base_assertions;
if (count($notif_types) === 1) {

View File

@ -703,16 +703,13 @@ class ArgumentsAnalyzer
}
}
if (ArrayFunctionArgumentsAnalyzer::checkArgumentsMatch(
ArrayFunctionArgumentsAnalyzer::checkArgumentsMatch(
$statements_analyzer,
$context,
$args,
$method_id,
$context->check_functions
) === false
) {
return false;
}
);
return null;
}

View File

@ -44,7 +44,6 @@ class ArrayFunctionArgumentsAnalyzer
{
/**
* @param array<int, PhpParser\Node\Arg> $args
* @return false|null
*/
public static function checkArgumentsMatch(
StatementsAnalyzer $statements_analyzer,
@ -52,7 +51,7 @@ class ArrayFunctionArgumentsAnalyzer
array $args,
string $method_id,
bool $check_functions
) {
): void {
$closure_index = $method_id === 'array_map' ? 0 : 1;
$array_arg_types = [];

View File

@ -201,37 +201,35 @@ class Algebra
}
}
if ($assertions !== null) {
$clauses = [];
$clauses = [];
foreach ($assertions as $var => $anded_types) {
$redefined = false;
foreach ($assertions as $var => $anded_types) {
$redefined = false;
if ($var[0] === '=') {
/** @var string */
$var = substr($var, 1);
$redefined = true;
}
foreach ($anded_types as $orred_types) {
$clauses[] = new Clause(
[$var => $orred_types],
$conditional_object_id,
\spl_object_id($conditional->expr),
false,
true,
$orred_types[0][0] === '='
|| $orred_types[0][0] === '~'
|| (strlen($orred_types[0]) > 1
&& ($orred_types[0][1] === '='
|| $orred_types[0][1] === '~')),
$redefined ? [$var => true] : []
);
}
if ($var[0] === '=') {
/** @var string */
$var = substr($var, 1);
$redefined = true;
}
return self::negateFormula($clauses);
foreach ($anded_types as $orred_types) {
$clauses[] = new Clause(
[$var => $orred_types],
$conditional_object_id,
\spl_object_id($conditional->expr),
false,
true,
$orred_types[0][0] === '='
|| $orred_types[0][0] === '~'
|| (strlen($orred_types[0]) > 1
&& ($orred_types[0][1] === '='
|| $orred_types[0][1] === '~')),
$redefined ? [$var => true] : []
);
}
}
return self::negateFormula($clauses);
}
if ($conditional->expr instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd) {