mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Check from_docblock property to emit the right issue (#4736)
This commit is contained in:
parent
9789b53617
commit
4ded1080e3
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Psalm\Internal\Type;
|
namespace Psalm\Internal\Type;
|
||||||
|
|
||||||
|
use Psalm\Issue\RedundantConditionGivenDocblockType;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
use Psalm\Issue\ParadoxicalCondition;
|
use Psalm\Issue\ParadoxicalCondition;
|
||||||
@ -637,22 +638,29 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
|||||||
$existing_var_type->addType(new Type\Atomic\TNonEmptyMixed);
|
$existing_var_type->addType(new Type\Atomic\TNonEmptyMixed);
|
||||||
}
|
}
|
||||||
} elseif ($existing_var_type->isMixed() && !$is_equality) {
|
} elseif ($existing_var_type->isMixed() && !$is_equality) {
|
||||||
if ($code_location
|
if ($code_location && $key) {
|
||||||
&& $key
|
if ($existing_var_type->from_docblock) {
|
||||||
&& IssueBuffer::accepts(
|
$issue = new RedundantConditionGivenDocblockType(
|
||||||
new RedundantCondition(
|
|
||||||
'Found a redundant condition when evaluating ' . $key
|
'Found a redundant condition when evaluating ' . $key
|
||||||
. ' of type ' . $existing_var_type->getId()
|
. ' of type ' . $existing_var_type->getId()
|
||||||
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
||||||
$code_location,
|
$code_location,
|
||||||
$existing_var_type->getId() . ' ' . $assertion
|
$existing_var_type->getId() . ' ' . $assertion
|
||||||
),
|
);
|
||||||
$suppressed_issues
|
} else {
|
||||||
)
|
$issue = new RedundantCondition(
|
||||||
) {
|
'Found a redundant condition when evaluating ' . $key
|
||||||
|
. ' of type ' . $existing_var_type->getId()
|
||||||
|
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
||||||
|
$code_location,
|
||||||
|
$existing_var_type->getId() . ' ' . $assertion
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (IssueBuffer::accepts($issue, $suppressed_issues)) {
|
||||||
// fall through
|
// fall through
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($existing_var_type->isMixed()) {
|
if ($existing_var_type->isMixed()) {
|
||||||
return $existing_var_type;
|
return $existing_var_type;
|
||||||
@ -668,22 +676,29 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
|||||||
$existing_var_type->addType(new Type\Atomic\TNonEmptyScalar);
|
$existing_var_type->addType(new Type\Atomic\TNonEmptyScalar);
|
||||||
}
|
}
|
||||||
} elseif ($existing_var_type->isSingle() && !$is_equality) {
|
} elseif ($existing_var_type->isSingle() && !$is_equality) {
|
||||||
if ($code_location
|
if ($code_location && $key) {
|
||||||
&& $key
|
if ($existing_var_type->from_docblock) {
|
||||||
&& IssueBuffer::accepts(
|
$issue = new RedundantConditionGivenDocblockType(
|
||||||
new RedundantCondition(
|
|
||||||
'Found a redundant condition when evaluating ' . $key
|
'Found a redundant condition when evaluating ' . $key
|
||||||
. ' of type ' . $existing_var_type->getId()
|
. ' of type ' . $existing_var_type->getId()
|
||||||
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
||||||
$code_location,
|
$code_location,
|
||||||
$existing_var_type->getId() . ' ' . $assertion
|
$existing_var_type->getId() . ' ' . $assertion
|
||||||
),
|
);
|
||||||
$suppressed_issues
|
} else {
|
||||||
)
|
$issue = new RedundantCondition(
|
||||||
) {
|
'Found a redundant condition when evaluating ' . $key
|
||||||
|
. ' of type ' . $existing_var_type->getId()
|
||||||
|
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
||||||
|
$code_location,
|
||||||
|
$existing_var_type->getId() . ' ' . $assertion
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (IssueBuffer::accepts($issue, $suppressed_issues)) {
|
||||||
// fall through
|
// fall through
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($existing_var_type->isSingle()) {
|
if ($existing_var_type->isSingle()) {
|
||||||
return $existing_var_type;
|
return $existing_var_type;
|
||||||
@ -705,22 +720,29 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
|||||||
$existing_var_type->addType(new Type\Atomic\TNonEmptyString);
|
$existing_var_type->addType(new Type\Atomic\TNonEmptyString);
|
||||||
}
|
}
|
||||||
} elseif ($existing_var_type->isSingle() && !$is_equality) {
|
} elseif ($existing_var_type->isSingle() && !$is_equality) {
|
||||||
if ($code_location
|
if ($code_location && $key) {
|
||||||
&& $key
|
if ($existing_var_type->from_docblock) {
|
||||||
&& IssueBuffer::accepts(
|
$issue = new RedundantConditionGivenDocblockType(
|
||||||
new RedundantCondition(
|
|
||||||
'Found a redundant condition when evaluating ' . $key
|
'Found a redundant condition when evaluating ' . $key
|
||||||
. ' of type ' . $existing_var_type->getId()
|
. ' of type ' . $existing_var_type->getId()
|
||||||
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
||||||
$code_location,
|
$code_location,
|
||||||
$existing_var_type->getId() . ' ' . $assertion
|
$existing_var_type->getId() . ' ' . $assertion
|
||||||
),
|
);
|
||||||
$suppressed_issues
|
} else {
|
||||||
)
|
$issue = new RedundantCondition(
|
||||||
) {
|
'Found a redundant condition when evaluating ' . $key
|
||||||
|
. ' of type ' . $existing_var_type->getId()
|
||||||
|
. ' and trying to reconcile it with a non-' . $assertion . ' assertion',
|
||||||
|
$code_location,
|
||||||
|
$existing_var_type->getId() . ' ' . $assertion
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (IssueBuffer::accepts($issue, $suppressed_issues)) {
|
||||||
// fall through
|
// fall through
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($existing_var_type->isSingle()) {
|
if ($existing_var_type->isSingle()) {
|
||||||
return $existing_var_type;
|
return $existing_var_type;
|
||||||
|
@ -1480,7 +1480,7 @@ class AssertAnnotationTest extends TestCase
|
|||||||
|
|
||||||
if ($bar) {}
|
if ($bar) {}
|
||||||
}',
|
}',
|
||||||
'error_message' => 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:19:29',
|
'error_message' => 'RedundantConditionGivenDocblockType - src' . DIRECTORY_SEPARATOR . 'somefile.php:19:29',
|
||||||
],
|
],
|
||||||
'assertOneOfStrings' => [
|
'assertOneOfStrings' => [
|
||||||
'<?php
|
'<?php
|
||||||
|
@ -1882,7 +1882,7 @@ class FunctionCallTest extends TestCase
|
|||||||
|
|
||||||
if ($s) {}
|
if ($s) {}
|
||||||
}',
|
}',
|
||||||
'error_message' => 'RedundantCondition',
|
'error_message' => 'RedundantConditionGivenDocblockType',
|
||||||
],
|
],
|
||||||
'strposNoSetFirstParam' => [
|
'strposNoSetFirstParam' => [
|
||||||
'<?php
|
'<?php
|
||||||
|
Loading…
Reference in New Issue
Block a user