Skip to content

Commit

Permalink
Use isInteger() (#3571)
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Apr 8, 2023
1 parent 437cc5a commit 59cdfc8
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/NodeTypeResolver/NodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function getNativeType(Expr $expr): Type
public function isNumberType(Expr $expr): bool
{
$nodeType = $this->getType($expr);
if ($nodeType instanceof IntegerType) {
if ($nodeType->isInteger()->yes()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function isScalarType(Type $type): bool
return true;
}

if ($type instanceof IntegerType) {
if ($type->isInteger()->yes()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function areEqualScalar(Type $firstType, Type $secondType): bool
return $firstTypeClass === $secondTypeClass;
}

if ($firstType instanceof IntegerType && $secondType instanceof IntegerType) {
if ($firstType->isInteger()->yes() && $secondType->isInteger()->yes()) {
return true;
}

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

if ($type instanceof IntegerType) {
if ($type->isInteger()->yes()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function isScalar(UnionType $unionType): bool
continue;
}

if ($type instanceof IntegerType) {
if ($type->isInteger()->yes()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private function isPairClassTooDetailed(Type $itemType): bool

private function isIntegerKeyAndNonNestedArray(ArrayType $arrayType): bool
{
if (! $arrayType->getKeyType() instanceof IntegerType) {
if (! $arrayType->getKeyType()->isInteger()->yes()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function correctItemByParameterReflection(
$clearParameterType = TypeCombinator::removeNull($parameterType);

// correct type
if ($clearParameterType instanceof IntegerType && $item instanceof String_) {
if ($clearParameterType->isInteger()->yes() && $item instanceof String_) {
return new LNumber((int) $item->value);
}

Expand Down
2 changes: 1 addition & 1 deletion rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private function resolveNewConditionNode(Expr $expr, bool $isNegated): ?BinaryOp
}

$exprType = $this->getType($expr);
if ($exprType instanceof IntegerType) {
if ($exprType->isInteger()->yes()) {
return $this->resolveInteger($isNegated, $expr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function refactor(Node $node): ?Node
}

$secondArgType = $this->getType($node->args[2]->value);
if ($secondArgType instanceof IntegerType) {
if ($secondArgType->isInteger()->yes()) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/Php80/NodeAnalyzer/SwitchAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function hasDifferentTypeCases(array $cases, Expr $expr): bool
$uniqueTypes = $this->typeFactory->uniquateTypes($types);
$countUniqueTypes = count($uniqueTypes);

if ($countUniqueTypes === 1 && $uniqueTypes[0] instanceof IntegerType) {
if ($countUniqueTypes === 1 && $uniqueTypes[0]->isInteger()->yes()) {
$switchCondType = $this->nodeTypeResolver->getType($expr);
if (! $switchCondType instanceof MixedType && $switchCondType->isString()->maybe()) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions rules/Strict/NodeFactory/ExactCompareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function createIdenticalFalsyCompare(
return new Identical($expr, new String_(''));
}

if ($exprType instanceof IntegerType) {
if ($exprType->isInteger()->yes()) {
return new Identical($expr, new LNumber(0));
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public function createNotIdenticalFalsyCompare(
return new NotIdentical($expr, new String_(''));
}

if ($exprType instanceof IntegerType) {
if ($exprType->isInteger()->yes()) {
return new NotIdentical($expr, new LNumber(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function isScalarType(Type $type): bool
return true;
}

if ($type instanceof IntegerType) {
if ($type->isInteger()->yes()) {
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static function (Node $subNode): bool {

if ($resolvedType instanceof UnionType) {
$benevolentUnionTypeIntegerType = $this->resolveBenevolentUnionTypeInteger($functionLike, $resolvedType);
if ($benevolentUnionTypeIntegerType instanceof IntegerType) {
if ($benevolentUnionTypeIntegerType->isInteger()->yes()) {
return $benevolentUnionTypeIntegerType;
}
}
Expand All @@ -157,15 +157,15 @@ static function (Node $subNode): bool {
private function resolveBenevolentUnionTypeInteger(
ClassMethod|Function_|Closure|ArrowFunction $functionLike,
UnionType $unionType
): UnionType|IntegerType {
): Type {
$types = $unionType->getTypes();
$countTypes = count($types);

if ($countTypes !== 2) {
return $unionType;
}

if (! ($types[0] instanceof IntegerType && $types[1]->isString()->yes())) {
if (! ($types[0]->isInteger()->yes() && $types[1]->isString()->yes())) {
return $unionType;
}

Expand Down

0 comments on commit 59cdfc8

Please sign in to comment.