Skip to content

Commit

Permalink
Use isBoolean() (#3570)
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Apr 8, 2023
1 parent 7611dcb commit 437cc5a
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 29 deletions.
Expand Up @@ -64,7 +64,7 @@ private function isScalarType(Type $type): bool
return true;
}

if ($type instanceof BooleanType) {
if ($type->isBoolean()->yes()) {
return true;
}

Expand Down
Expand Up @@ -34,11 +34,11 @@ public function areEqualScalar(Type $firstType, Type $secondType): bool
return true;
}

if (! $firstType instanceof BooleanType) {
if (! $firstType->isBoolean()->yes()) {
return false;
}

return $secondType instanceof BooleanType;
return $secondType->isBoolean()->yes();
}

/**
Expand Down Expand Up @@ -84,6 +84,6 @@ private function isScalarType(Type $type): bool
return true;
}

return $type instanceof BooleanType;
return $type->isBoolean()->yes();
}
}
Expand Up @@ -13,7 +13,7 @@ final class BoolUnionTypeAnalyzer
public function isBoolUnionType(UnionType $unionType): bool
{
foreach ($unionType->getTypes() as $unionedType) {
if (! $unionedType instanceof BooleanType) {
if (! $unionedType->isBoolean()->yes()) {
return false;
}
}
Expand All @@ -30,7 +30,7 @@ public function isNullableBoolUnionType(UnionType $unionType): bool
continue;
}

if ($unionedType instanceof BooleanType) {
if ($unionedType->isBoolean()->yes()) {
continue;
}

Expand Down
Expand Up @@ -122,7 +122,7 @@ public function isScalar(UnionType $unionType): bool
continue;
}

if ($type instanceof BooleanType) {
if ($type->isBoolean()->yes()) {
continue;
}

Expand Down
Expand Up @@ -96,7 +96,7 @@ private function correctItemByParameterReflection(
return new LNumber((int) $item->value);
}

if ($clearParameterType instanceof BooleanType && $item instanceof String_) {
if ($clearParameterType->isBoolean()->yes() && $item instanceof String_) {
if (strtolower($item->value) === 'true') {
return $this->nodeFactory->createTrue();
}
Expand Down
2 changes: 1 addition & 1 deletion rules/CodeQuality/NodeManipulator/ExprBoolCaster.php
Expand Up @@ -61,7 +61,7 @@ private function isBoolCastNeeded(Expr $expr): bool
}

$exprType = $this->nodeTypeResolver->getType($expr);
if ($exprType instanceof BooleanType) {
if ($exprType->isBoolean()->yes()) {
return false;
}

Expand Down
Expand Up @@ -93,7 +93,7 @@ private function processExplicitIf(Expression $expression): ?Node
$booleanExpr = $expression->expr;

$leftStaticType = $this->getType($booleanExpr->left);
if (! $leftStaticType instanceof BooleanType) {
if (! $leftStaticType->isBoolean()->yes()) {
return null;
}

Expand Down
Expand Up @@ -80,12 +80,12 @@ public function refactor(Node $node): ?Node
$identical = $node->expr;

$leftType = $this->getType($identical->left);
if (! $leftType instanceof BooleanType) {
if (! $leftType->isBoolean()->yes()) {
return null;
}

$rightType = $this->getType($identical->right);
if (! $rightType instanceof BooleanType) {
if (! $rightType->isBoolean()->yes()) {
return null;
}

Expand All @@ -98,12 +98,12 @@ public function refactor(Node $node): ?Node
private function processIdentical(Identical $identical): ?NotIdentical
{
$leftType = $this->getType($identical->left);
if (! $leftType instanceof BooleanType) {
if (! $leftType->isBoolean()->yes()) {
return null;
}

$rightType = $this->getType($identical->right);
if (! $rightType instanceof BooleanType) {
if (! $rightType->isBoolean()->yes()) {
return null;
}

Expand Down
Expand Up @@ -66,12 +66,12 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
$leftType = $this->getType($node->left);
if ($leftType instanceof BooleanType && ! $this->valueResolver->isTrueOrFalse($node->left)) {
if ($leftType->isBoolean()->yes() && ! $this->valueResolver->isTrueOrFalse($node->left)) {
return $this->processBoolTypeToNotBool($node, $node->left, $node->right);
}

$rightType = $this->getType($node->right);
if (! $rightType instanceof BooleanType) {
if (! $rightType->isBoolean()->yes()) {
return null;
}

Expand Down Expand Up @@ -110,7 +110,7 @@ private function refactorIdentical(Expr $leftExpr, Expr $rightExpr): ?Expr
$leftExprType = $this->getType($leftExpr);

// keep as it is, readable enough
if ($leftExpr instanceof Variable && $leftExprType instanceof BooleanType) {
if ($leftExpr instanceof Variable && $leftExprType->isBoolean()->yes()) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php
Expand Up @@ -111,7 +111,7 @@ public function refactor(Node $node): ?Node
}

$conditionStaticType = $this->getType($conditionNode);
if ($conditionStaticType instanceof BooleanType) {
if ($conditionStaticType->isBoolean()->yes()) {
return null;
}

Expand Down
Expand Up @@ -111,7 +111,7 @@ private function processNonBinaryCondition(Expr $ifExpression, Expr $elseExpress
private function processTrueIfExpressionWithFalseElseExpression(Expr $expr): Expr
{
$exprType = $this->getType($expr);
if ($exprType instanceof BooleanType) {
if ($exprType->isBoolean()->yes()) {
return $expr;
}

Expand All @@ -122,15 +122,15 @@ private function processFalseIfExpressionWithTrueElseExpression(Expr $expr): Exp
{
if ($expr instanceof BooleanNot) {
$negatedExprType = $this->getType($expr->expr);
if ($negatedExprType instanceof BooleanType) {
if ($negatedExprType->isBoolean()->yes()) {
return $expr->expr;
}

return new Bool_($expr->expr);
}

$exprType = $this->getType($expr);
if ($exprType instanceof BooleanType) {
if ($exprType->isBoolean()->yes()) {
return new BooleanNot($expr);
}

Expand Down
Expand Up @@ -100,6 +100,6 @@ public function refactor(Node $node): ?Node
private function isBoolDocType(Property $property): bool
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
return $phpDocInfo->getVarType() instanceof BooleanType;
return $phpDocInfo->getVarType()->isBoolean()->yes();
}
}
Expand Up @@ -142,7 +142,7 @@ private function isBoolVarIfCondReturnTrueNextReturnBoolVar(array $ifWithOnlyRet
}

$type = $this->nodeTypeResolver->getType($cond);
if (! $type instanceof BooleanType) {
if (! $type->isBoolean()->yes()) {
return false;
}

Expand Down
Expand Up @@ -81,7 +81,7 @@ public function refactor(Node $node): ?Node
}

$ifType = $this->getType($node->if);
if (! $ifType instanceof BooleanType) {
if (! $ifType->isBoolean()->yes()) {
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions rules/Strict/NodeFactory/ExactCompareFactory.php
Expand Up @@ -44,7 +44,7 @@ public function createIdenticalFalsyCompare(
return new Identical($expr, new LNumber(0));
}

if ($exprType instanceof BooleanType) {
if ($exprType->isBoolean()->yes()) {
return new Identical($expr, $this->nodeFactory->createFalse());
}

Expand Down Expand Up @@ -94,7 +94,7 @@ private function createFromUnionType(
): Identical|Instanceof_|BooleanOr|NotIdentical|BooleanAnd|BooleanNot|null {
$unionType = TypeCombinator::removeNull($unionType);

if ($unionType instanceof BooleanType) {
if ($unionType->isBoolean()->yes()) {
return new Identical($expr, $this->nodeFactory->createTrue());
}

Expand Down Expand Up @@ -209,7 +209,7 @@ private function createTruthyFromUnionType(
return $this->createBooleanOr($compareExprs);
}

if ($unionType instanceof BooleanType) {
if ($unionType->isBoolean()->yes()) {
return new NotIdentical($expr, $this->nodeFactory->createTrue());
}

Expand Down
Expand Up @@ -131,7 +131,7 @@ private function isScalarType(Type $type): bool
return true;
}

return $type instanceof BooleanType;
return $type->isBoolean()->yes();
}

private function resolveTypeFromScalar(Scalar $scalar): Type|null
Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/Node/AssignAndBinaryMap.php
Expand Up @@ -133,7 +133,7 @@ public function getTruthyExpr(Expr $expr): Expr
}

$type = $scope->getType($expr);
if ($type instanceof BooleanType) {
if ($type->isBoolean()->yes()) {
return $expr;
}

Expand Down

0 comments on commit 437cc5a

Please sign in to comment.