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

Expand out class constants as early as possible

Fixes #3128
This commit is contained in:
Brown 2020-04-12 20:38:36 -04:00
parent 15df39f72f
commit 73f8f963fa
3 changed files with 36 additions and 6 deletions

View File

@ -185,7 +185,8 @@ class ArrayAssignmentAnalyzer
}
if ($child_stmt->dim instanceof PhpParser\Node\Scalar\String_
|| ($child_stmt->dim instanceof PhpParser\Node\Expr\ConstFetch
|| (($child_stmt->dim instanceof PhpParser\Node\Expr\ConstFetch
|| $child_stmt->dim instanceof PhpParser\Node\Expr\ClassConstFetch)
&& $child_stmt_dim_type->isSingleStringLiteral())
) {
if ($child_stmt->dim instanceof PhpParser\Node\Scalar\String_) {
@ -199,7 +200,8 @@ class ArrayAssignmentAnalyzer
}
$var_id_additions[] = '[\'' . $value . '\']';
} elseif ($child_stmt->dim instanceof PhpParser\Node\Scalar\LNumber
|| ($child_stmt->dim instanceof PhpParser\Node\Expr\ConstFetch
|| (($child_stmt->dim instanceof PhpParser\Node\Expr\ConstFetch
|| $child_stmt->dim instanceof PhpParser\Node\Expr\ClassConstFetch)
&& $child_stmt_dim_type->isSingleIntLiteral())
) {
if ($child_stmt->dim instanceof PhpParser\Node\Scalar\LNumber) {

View File

@ -82,16 +82,16 @@ class ArrayFetchAnalyzer
$statements_analyzer
);
if ($stmt->dim && ExpressionAnalyzer::analyze($statements_analyzer, $stmt->dim, $context) === false) {
return false;
}
$keyed_array_var_id = ExpressionAnalyzer::getArrayVarId(
$stmt,
$statements_analyzer->getFQCLN(),
$statements_analyzer
);
if ($stmt->dim && ExpressionAnalyzer::analyze($statements_analyzer, $stmt->dim, $context) === false) {
return false;
}
$dim_var_id = null;
$new_offset_type = null;

View File

@ -916,6 +916,34 @@ class IssetTest extends \Psalm\Tests\TestCase
}
}',
],
'issetOnClassConstantOffset' => [
'<?php
final class StudyJwtPayload {
public const STUDY_ID = "studid";
public static function fromClaims(array $claims): string
{
if (!isset($claims["usrid"])) {
throw new \InvalidArgumentException();
}
if (!\is_string($claims["usrid"])) {
throw new \InvalidArgumentException();
}
if (!isset($claims[self::STUDY_ID])) {
throw new \InvalidArgumentException();
}
if (!\is_string($claims[self::STUDY_ID])) {
throw new \InvalidArgumentException();
}
return $claims[self::STUDY_ID];
}
}'
],
];
}