Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c98de02
use isClassStringType() on ScalarTypeComparator
samsonasik Nov 11, 2024
c122e9f
Fix false constant via isFalse()->yes() on ReduceAlwaysFalseIfOrRector
samsonasik Nov 11, 2024
8130ac1
use isBoolean()->yes() on BoolReturnTypeFromBooleanStrictReturnsRector
samsonasik Nov 11, 2024
6927254
use ->isNull()->yes() on CallerParamMatcher
samsonasik Nov 11, 2024
75a1e39
use ->isVoid()->yes() on ExplicitReturnNullRector
samsonasik Nov 11, 2024
030dcf1
use ->isConstantValue()->yes() on ContinueToBreakInSwitchRector
samsonasik Nov 11, 2024
e165382
use ->isCallable()->yes() on UnionTypeMapper
samsonasik Nov 11, 2024
00b15dc
use ->isNull()->yes() on TypeExpressionFromVarTagResolver
samsonasik Nov 11, 2024
256b14b
use ->isNull()->yes() on SimplifyIfNullableReturnRector
samsonasik Nov 11, 2024
49d632b
use ->isConstantValue()->yes() on RemoveZeroBreakContinueRector
samsonasik Nov 11, 2024
a8f874e
[ci-review] Rector Rectify
actions-user Nov 11, 2024
67f5b19
use ->isNull()->yes() on GetClassOnNullRector
samsonasik Nov 11, 2024
0565f10
use ->isNull()->yes() on NullToStrictStringFuncCallArgRector
samsonasik Nov 11, 2024
c04cfa5
use ->isNull()->yes() on ExactCompareFactory
samsonasik Nov 11, 2024
a2dd5a2
replace instanceof NullType to isNull()->yes()
samsonasik Nov 11, 2024
b55e612
cs
samsonasik Nov 11, 2024
044e2a2
use isInteger()->yes() on AnnotationToAttributeIntegerValueCaster
samsonasik Nov 11, 2024
e61c7ba
use isCallable()->yes() over instanceof CallableType
samsonasik Nov 11, 2024
bd798e9
use ->isArray()->yes() on PropertyTypeDefaultValueAnalyzer
samsonasik Nov 11, 2024
ec07695
use ->isTrue()->yes() on RemoveAlwaysTrueIfConditionRector
samsonasik Nov 11, 2024
dd79e4d
unwrapFirstCallableTypeFromUnionType never return null
samsonasik Nov 11, 2024
8d347b6
use isTrue()->yes() and isFalse()->yes() on TypeFactory
samsonasik Nov 11, 2024
f8b63fd
use ->isArray()->yes() on DoctrineTypeAnalyzer
samsonasik Nov 11, 2024
1e4917d
use ->isTrue()->yes() and isFalse()->yes() on BooleanTypeMapper
samsonasik Nov 11, 2024
4cc9769
use ->isTrue()->yes() and isFalse()->yes() on TypeComparator
samsonasik Nov 11, 2024
6001549
rollback fixture file replace
samsonasik Nov 11, 2024
2c62788
use ->isArray()->yes() on RemoveAlwaysTrueIfConditionRector
samsonasik Nov 11, 2024
c04877c
rollback isCallable() usage on AddClosureParamTypeFromIterableMethodC…
samsonasik Nov 11, 2024
ca20a56
use ->isArray()->yes() on SimplifyEmptyCheckOnEmptyArrayRector
samsonasik Nov 11, 2024
c128c96
use ->isArray()->yes() on ArrayTypeMapper
samsonasik Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpParser\NodeTraverser;
use PHPStan\Type\NullType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
Expand Down Expand Up @@ -157,7 +156,7 @@ private function transformDocUnionVoidToUnionNull(ClassMethod|Function_ $node):
$newTypes = [];
$hasChanged = false;
foreach ($returnType->getTypes() as $type) {
if ($type instanceof VoidType) {
if ($type->isVoid()->yes()) {
$type = new NullType();
$hasChanged = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use PhpParser\Node\Stmt\Property;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\Php\ReservedKeywordAnalyzer;
use Rector\PhpParser\AstResolver;
Expand Down Expand Up @@ -104,7 +104,7 @@ private function isAllowedVariable(Variable $variable): bool

private function isAllowedExpr(Expr $expr, Scope $scope): bool
{
if (! $scope->getType($expr) instanceof ArrayType) {
if (! $scope->getType($expr)->isArray()->yes()) {
return false;
}

Expand Down Expand Up @@ -134,7 +134,8 @@ private function isAllowedExpr(Expr $expr, Scope $scope): bool
$nativeType = $phpPropertyReflection->getNativeType();

if (! $nativeType instanceof MixedType) {
return $nativeType instanceof ArrayType;
return $nativeType->isArray()
->yes();
}

$property = $this->astResolver->resolvePropertyFromPropertyReflection($phpPropertyReflection);
Expand All @@ -150,6 +151,11 @@ private function isAllowedExpr(Expr $expr, Scope $scope): bool
}

$type = $this->allAssignNodePropertyTypeInferer->inferProperty($property, $classReflection, $this->file);
return $type instanceof ArrayType;
if (! $type instanceof Type) {
return false;
}

return $type->isArray()
->yes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
Expand Down Expand Up @@ -225,11 +224,11 @@ private function processSimplifyNullableReturn(
return null;
}

if ($types[0] instanceof FullyQualifiedObjectType && $types[1] instanceof NullType && $className === $types[0]->getClassName()) {
if ($types[0] instanceof FullyQualifiedObjectType && $types[1]->isNull()->yes() && $className === $types[0]->getClassName()) {
return $this->createDirectReturn($expression, $expr, $unionType);
}

if ($types[0] instanceof NullType && $types[1] instanceof FullyQualifiedObjectType && $className === $types[1]->getClassName()) {
if ($types[0]->isNull()->yes() && $types[1] instanceof FullyQualifiedObjectType && $className === $types[1]->getClassName()) {
return $this->createDirectReturn($expression, $expr, $unionType);
}

Expand All @@ -249,7 +248,7 @@ private function isNotTypedNullable(array $types, string $className): bool
return true;
}

if (! $types[1] instanceof NullType) {
if (! $types[1]->isNull()->yes()) {
return true;
}

Expand Down
7 changes: 1 addition & 6 deletions rules/DeadCode/Rector/If_/ReduceAlwaysFalseIfOrRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Stmt\If_;
use PHPStan\Type\Constant\ConstantBooleanType;
use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -79,11 +78,7 @@ public function refactor(Node $node): ?Node
$booleanOr = $node->cond;

$conditionStaticType = $this->getType($booleanOr->left);
if (! $conditionStaticType instanceof ConstantBooleanType) {
return null;
}

if ($conditionStaticType->getValue()) {
if (! $conditionStaticType->isFalse()->yes()) {
return null;
}

Expand Down
16 changes: 3 additions & 13 deletions rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
use PhpParser\NodeTraverser;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\IntersectionType;
use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer;
use Rector\NodeAnalyzer\ExprAnalyzer;
Expand Down Expand Up @@ -101,11 +99,7 @@ public function refactor(Node $node): int|null|array|If_
}

$conditionStaticType = $this->getType($node->cond);
if (! $conditionStaticType instanceof ConstantBooleanType) {
return null;
}

if (! $conditionStaticType->getValue()) {
if (! $conditionStaticType->isTrue()->yes()) {
return null;
}

Expand Down Expand Up @@ -142,7 +136,7 @@ private function shouldSkipFromVariable(Expr $expr): bool
$type = $this->getType($variable);
if ($type instanceof IntersectionType) {
foreach ($type->getTypes() as $subType) {
if ($subType instanceof ArrayType) {
if ($subType->isArray()->yes()) {
return true;
}
}
Expand Down Expand Up @@ -175,11 +169,7 @@ private function refactorIfWithBooleanAnd(If_ $if): ?If_
$booleanAnd = $if->cond;

$leftType = $this->getType($booleanAnd->left);
if (! $leftType instanceof ConstantBooleanType) {
return null;
}

if (! $leftType->getValue()) {
if (! $leftType->isTrue()->yes()) {
return null;
}

Expand Down
3 changes: 1 addition & 2 deletions rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PhpParser\Node\Stmt\While_;
use PhpParser\NodeTraverser;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\ConstantType;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -153,7 +152,7 @@ function (Node $subNode): null|int|Break_ {
private function processVariableNum(Continue_ $continue, Variable $numVariable): Continue_ | Break_
{
$staticType = $this->getType($numVariable);
if (! $staticType instanceof ConstantType) {
if (! $staticType->isConstantValue()->yes()) {
return $continue;
}

Expand Down
3 changes: 1 addition & 2 deletions rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Continue_;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\ConstantType;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
Expand Down Expand Up @@ -115,7 +114,7 @@ private function processVariableNum(Break_ | Continue_ $stmt, Variable $numVaria
{
$staticType = $this->getType($numVariable);

if ($staticType instanceof ConstantType) {
if ($staticType->isConstantValue()->yes()) {
if ($staticType instanceof ConstantIntegerType) {
if ($staticType->getValue() === 0) {
$stmt->num = null;
Expand Down
3 changes: 1 addition & 2 deletions rules/Php72/Rector/FuncCall/GetClassOnNullRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope;
use PHPStan\Type\NullType;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\ValueObject\PhpVersionFeature;
Expand Down Expand Up @@ -104,7 +103,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
$firstArgValue = $firstArg->value;

$firstArgType = $this->getType($firstArgValue);
if (! $this->nodeTypeResolver->isNullableType($firstArgValue) && ! $firstArgType instanceof NullType) {
if (! $this->nodeTypeResolver->isNullableType($firstArgValue) && ! $firstArgType->isNull()->yes()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Type\ErrorType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use Rector\NodeAnalyzer\ArgsAnalyzer;
Expand Down Expand Up @@ -263,7 +262,7 @@ private function isValidUnionType(Type $type): bool
private function shouldSkipType(Type $type): bool
{
return ! $type instanceof MixedType &&
! $type instanceof NullType &&
! $type->isNull()->yes() &&
! $this->isValidUnionType($type);
}

Expand Down
3 changes: 1 addition & 2 deletions rules/Strict/NodeFactory/ExactCompareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeWithClassName;
Expand Down Expand Up @@ -55,7 +54,7 @@ public function createIdenticalFalsyCompare(
return new Identical($expr, $this->nodeFactory->createFalse());
} elseif ($exprType->isArray()->yes()) {
return new Identical($expr, new Array_([]));
} elseif ($exprType instanceof NullType) {
} elseif ($exprType->isNull()->yes()) {
return new Identical($expr, $this->nodeFactory->createNull());
} elseif (! $exprType instanceof UnionType) {
return null;
Expand Down
3 changes: 1 addition & 2 deletions rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpParser\Node\Identifier;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -108,7 +107,7 @@ private function unionToSingleType(array $staticTypesByArgumentPosition): array
return $staticTypeByArgumentPosition;
}

if (! $staticTypeByArgumentPosition[0] instanceof NullType) {
if (! $staticTypeByArgumentPosition[0]->isNull()->yes()) {
return $staticTypeByArgumentPosition;
}

Expand Down
3 changes: 1 addition & 2 deletions rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
use Rector\PhpParser\AstResolver;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function matchCallParamType(
return $callParam->type;
}

if (! $defaultType instanceof NullType) {
if (! $defaultType->isNull()->yes()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\CallableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -126,11 +125,11 @@ private function shouldSkipArgumentStaticType(

private function isClosureAndCallableType(Type $parameterStaticType, Type $argumentStaticType): bool
{
if ($parameterStaticType instanceof CallableType && $this->isClosureObjectType($argumentStaticType)) {
if ($parameterStaticType->isCallable()->yes() && $this->isClosureObjectType($argumentStaticType)) {
return true;
}

return $argumentStaticType instanceof CallableType && $this->isClosureObjectType($parameterStaticType);
return $argumentStaticType->isCallable()->yes() && $this->isClosureObjectType($parameterStaticType);
}

private function isClosureObjectType(Type $type): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareIntersectionTypeNode;
Expand All @@ -49,7 +48,7 @@ public function resolveTypeExpressionFromVarTag(TypeNode $typeNode, Variable $va
return new FuncCall(new Name($scalarTypeFunction), [$arg]);
}

if ($scalarType instanceof NullType) {
if ($scalarType->isNull()->yes()) {
return new Identical($variable, new ConstFetch(new Name('null')));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use PhpParser\Node\Stmt\Return_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\BooleanType;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractScopeAwareRector;
Expand Down Expand Up @@ -181,10 +180,12 @@ private function isNativeBooleanReturnTypeFuncCall(FuncCall $funcCall): bool
}

foreach ($functionReflection->getVariants() as $parametersAcceptorWithPhpDoc) {
return $parametersAcceptorWithPhpDoc->getNativeReturnType() instanceof BooleanType;
if (! $parametersAcceptorWithPhpDoc->getNativeReturnType()->isBoolean()->yes()) {
return false;
}
}

return false;
return true;
}

private function isBooleanOp(Expr $expr): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\UnionType as PhpParserUnionType;
use PHPStan\Analyser\Scope;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\UnionType;
use Rector\Php\PhpVersionProvider;
Expand Down Expand Up @@ -175,7 +174,7 @@ private function processSingleUnionType(
NullableType $nullableType
): Closure | ClassMethod | Function_ {
$types = $unionType->getTypes();
$returnType = $types[0] instanceof ObjectType && $types[1] instanceof NullType
$returnType = $types[0] instanceof ObjectType && $types[1]->isNull()->yes()
? new NullableType(new FullyQualified($types[0]->getClassName()))
: $nullableType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\PropertyProperty;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Type;
use Rector\StaticTypeMapper\StaticTypeMapper;

Expand All @@ -25,7 +24,7 @@ public function doesConflictWithDefaultValue(PropertyProperty $propertyProperty,

// the defaults can be in conflict
$defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($propertyProperty->default);
if ($defaultType instanceof ArrayType && $propertyType instanceof ArrayType) {
if ($defaultType->isArray()->yes() && $propertyType->isArray()->yes()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function isParamNullable(Param $param): bool

if ($param->default instanceof Expr) {
$defaultValueStaticType = $this->nodeTypeResolver->getType($param->default);
if ($defaultValueStaticType instanceof NullType) {
if ($defaultValueStaticType->isNull()->yes()) {
return true;
}
}
Expand Down
Loading