Skip to content

Commit

Permalink
Support isNotA
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Feb 28, 2022
1 parent 5b5916d commit 11cc4ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This extension specifies types of values passed to:
* `Assert::notInstanceOf`
* `Assert::isAOf`
* `Assert::isAnyOf`
* `Assert::isNotA`
* `Assert::subclassOf`
* `Assert::true`
* `Assert::false`
Expand Down
3 changes: 3 additions & 0 deletions src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ private static function getExpressionResolvers(): array
'isAnyOf' => static function (Scope $scope, Arg $value, Arg $classes): ?Expr {
return self::buildAnyOfExpr($scope, $value, $classes, self::$resolvers['isAOf']);
},
'isNotA' => static function (Scope $scope, Arg $value, Arg $class): Expr {
return new BooleanNot(self::$resolvers['isAOf']($scope, $value, $class));
},
'implementsInterface' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
$classType = $scope->getType($class->value);
if (!$classType instanceof ConstantStringType) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Type/WebMozartAssert/data/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,29 @@ public function isAnyOf($a, $b): void
\PHPStan\Testing\assertType('\'PHPStan\\\Type\\\WebMozartAssert\\\Bar\'', Bar::class);
}

/**
* @param DateTimeImmutable|stdClass $a
* @param class-string<DateTimeImmutable>|class-string<stdClass> $b
* @param DateTimeImmutable|stdClass|null $c
*/
public function isNotA(object $a, string $b, ?object $c): void
{
Assert::isNotA($a, stdClass::class);
\PHPStan\Testing\assertType('DateTimeImmutable', $a);

Assert::isNotA($b, stdClass::class);
\PHPStan\Testing\assertType('class-string<DateTimeImmutable>', $b);

Assert::nullOrIsNotA($c, stdClass::class);
\PHPStan\Testing\assertType('DateTimeImmutable|null', $c);

Assert::isNotA(Foo::class, stdClass::class);
\PHPStan\Testing\assertType('\'PHPStan\\\Type\\\WebMozartAssert\\\Foo\'', Foo::class);

Assert::isNotA(Bar::class, stdClass::class);
\PHPStan\Testing\assertType('*NEVER*', Bar::class);
}

public function isArrayAccessible($a, $b): void
{
Assert::isArrayAccessible($a);
Expand Down

0 comments on commit 11cc4ba

Please sign in to comment.