Skip to content
Permalink
Browse files

Improve assertions support a bit more

  • Loading branch information
muglug committed Dec 30, 2019
1 parent 19faa31 commit 366e2d30a3813561a512fb47e34402dad5433439
@@ -336,7 +336,11 @@ public static function scrapeAssertions(
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 @@ public function newInstanceArgs(array $args): object {}
* @return T
*/
public function newInstanceWithoutConstructor(): object;

/**
* @return ?array<string>
* @psalm-ignore-nullable-return
*/
public function getTraitNames(): array {}
}

/**
@@ -794,6 +794,34 @@ function foo(A $a) : void {
}
}'
],
'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());
}'
],
];
}

0 comments on commit 366e2d3

Please sign in to comment.
You can’t perform that action at this time.