Skip to content

Commit

Permalink
Refactor BooleanNot usage
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Feb 23, 2022
1 parent 0e496ac commit af6e2f5
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,12 @@ static function (?ArrayItem $class) use ($scope, $expr) {
return self::implodeExpr($resolvers, BooleanOr::class);
},
'notInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
$classType = $scope->getType($class->value);
if ($classType instanceof ConstantStringType) {
$className = new Name($classType->getValue());
} elseif ($classType instanceof TypeWithClassName) {
$className = new Name($classType->getClassName());
} else {
$expr = self::$resolvers['isInstanceOf']($scope, $expr, $class);
if ($expr === null) {
return null;
}

return new BooleanNot(
new Instanceof_(
$expr->value,
$className
)
);
return new BooleanNot($expr);
},
'isAOf' => static function (Scope $scope, Arg $expr, Arg $class): Expr {
$exprType = $scope->getType($expr->value);
Expand Down Expand Up @@ -432,12 +423,7 @@ static function (?ArrayItem $class) use ($scope, $expr) {
);
},
'keyNotExists' => static function (Scope $scope, Arg $array, Arg $key): Expr {
return new BooleanNot(
new FuncCall(
new Name('array_key_exists'),
[$key, $array]
)
);
return new BooleanNot(self::$resolvers['keyExists']($scope, $array, $key));
},
'validArrayKey' => static function (Scope $scope, Arg $value): Expr {
return new BooleanOr(
Expand Down

0 comments on commit af6e2f5

Please sign in to comment.