1
0
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:
Matthew Brown 2018-11-29 23:25:30 -05:00
parent 21f29e7385
commit 9efd40e321
2 changed files with 27 additions and 0 deletions

View File

@ -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) {

View File

@ -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 {}