mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Improve assertions support a bit more
This commit is contained in:
parent
19faa31865
commit
366e2d30a3
@ -336,7 +336,11 @@ class AssertionFinder
|
||||
if ($conditional instanceof PhpParser\Node\Expr\MethodCall
|
||||
|| $conditional instanceof PhpParser\Node\Expr\StaticCall
|
||||
) {
|
||||
$if_types += self::processCustomAssertion($conditional, $this_class_name, $source, false);
|
||||
$custom_assertions = self::processCustomAssertion($conditional, $this_class_name, $source, false);
|
||||
|
||||
if ($custom_assertions) {
|
||||
return $custom_assertions;
|
||||
}
|
||||
|
||||
return $if_types;
|
||||
}
|
||||
|
@ -1340,6 +1340,12 @@ class ReflectionClass implements Reflector {
|
||||
* @return T
|
||||
*/
|
||||
public function newInstanceWithoutConstructor(): object;
|
||||
|
||||
/**
|
||||
* @return ?array<string>
|
||||
* @psalm-ignore-nullable-return
|
||||
*/
|
||||
public function getTraitNames(): array {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -794,6 +794,34 @@ class AssertAnnotationTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'assertOnThisMethod' => [
|
||||
'<?php
|
||||
/** @psalm-immutable */
|
||||
class A {
|
||||
private ?array $arr = null;
|
||||
|
||||
public function __construct(?array $arr) {
|
||||
$this->arr = $arr;
|
||||
}
|
||||
|
||||
/** @psalm-assert-if-true !null $this->getarray() */
|
||||
public function hasArray() : bool {
|
||||
return $this->arr !== null;
|
||||
}
|
||||
|
||||
public function getArray() : ?array {
|
||||
return $this->arr;
|
||||
}
|
||||
}
|
||||
|
||||
function foo(A $a) : void {
|
||||
if (!$a->hasArray()) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo count($a->getArray());
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user