mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #1095 - prevent complex assertion redundant condition
This commit is contained in:
parent
21f29e7385
commit
9efd40e321
@ -1052,6 +1052,11 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
|
||||
$rules = \Psalm\Type\Algebra::getTruthsFromFormula($negated_formula);
|
||||
|
||||
if (!$rules) {
|
||||
$var_assertions = [];
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($rules as $var_id => $rule) {
|
||||
foreach ($rule as $rule_part) {
|
||||
if (count($rule_part) > 1) {
|
||||
|
@ -124,6 +124,28 @@ class AssertTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'assertWithoutRedundantCondition' => [
|
||||
'<?php
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @throws \Exception
|
||||
*/
|
||||
function assertIsLongString($data): void {
|
||||
if (!is_string($data)) {
|
||||
throw new Exception;
|
||||
}
|
||||
if (strlen($data) < 100) {
|
||||
throw new Exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
function f(string $s): void {
|
||||
assertIsLongString($s);
|
||||
}',
|
||||
],
|
||||
'assertInstanceOfBAnnotation' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user