mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit dbb0e196a43d8c14a9de6abeef8fe081e95c51c2
dbb0e196a4
Revert all is* changes (#3584)
This commit is contained in:
parent
9d60770133
commit
3da290e4ab
@ -23,6 +23,8 @@ use PHPStan\Broker\ClassAutoloadingException;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\Constant\ConstantBooleanType;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
@ -240,10 +242,10 @@ final class NodeTypeResolver
|
||||
public function isNumberType(Expr $expr) : bool
|
||||
{
|
||||
$nodeType = $this->getType($expr);
|
||||
if ($nodeType->isInteger()->yes()) {
|
||||
if ($nodeType instanceof IntegerType) {
|
||||
return \true;
|
||||
}
|
||||
return $nodeType->isFloat()->yes();
|
||||
return $nodeType instanceof FloatType;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
|
@ -4,8 +4,11 @@ declare (strict_types=1);
|
||||
namespace Rector\NodeTypeResolver\PHPStan\Type;
|
||||
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
use PHPStan\Type\ConstantScalarType;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
@ -54,16 +57,16 @@ final class StaticTypeAnalyzer
|
||||
if ($type instanceof NullType) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isBoolean()->yes()) {
|
||||
if ($type instanceof BooleanType) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isString()->yes()) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isInteger()->yes()) {
|
||||
if ($type instanceof IntegerType) {
|
||||
return \true;
|
||||
}
|
||||
return $type->isFloat()->yes();
|
||||
return $type instanceof FloatType;
|
||||
}
|
||||
private function isAlwaysTruableUnionType(Type $type) : bool
|
||||
{
|
||||
|
@ -3,7 +3,11 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\NodeTypeResolver\TypeComparator;
|
||||
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\ClassStringType;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
/**
|
||||
* @see \Rector\Tests\NodeTypeResolver\TypeComparator\ScalarTypeComparatorTest
|
||||
@ -12,22 +16,22 @@ final class ScalarTypeComparator
|
||||
{
|
||||
public function areEqualScalar(Type $firstType, Type $secondType) : bool
|
||||
{
|
||||
if ($firstType->isString()->yes() && $secondType->isString()->yes()) {
|
||||
if ($firstType instanceof StringType && $secondType instanceof StringType) {
|
||||
// prevents "class-string" vs "string"
|
||||
$firstTypeClass = \get_class($firstType);
|
||||
$secondTypeClass = \get_class($secondType);
|
||||
return $firstTypeClass === $secondTypeClass;
|
||||
}
|
||||
if ($firstType->isInteger()->yes() && $secondType->isInteger()->yes()) {
|
||||
if ($firstType instanceof IntegerType && $secondType instanceof IntegerType) {
|
||||
return \true;
|
||||
}
|
||||
if ($firstType->isFloat()->yes() && $secondType->isFloat()->yes()) {
|
||||
if ($firstType instanceof FloatType && $secondType instanceof FloatType) {
|
||||
return \true;
|
||||
}
|
||||
if (!$firstType->isBoolean()->yes()) {
|
||||
if (!$firstType instanceof BooleanType) {
|
||||
return \false;
|
||||
}
|
||||
return $secondType->isBoolean()->yes();
|
||||
return $secondType instanceof BooleanType;
|
||||
}
|
||||
/**
|
||||
* E.g. first is string, second is bool
|
||||
@ -41,10 +45,10 @@ final class ScalarTypeComparator
|
||||
return \false;
|
||||
}
|
||||
// treat class-string and string the same
|
||||
if ($firstType instanceof ClassStringType && $secondType->isString()->yes()) {
|
||||
if ($firstType instanceof ClassStringType && $secondType instanceof StringType) {
|
||||
return \false;
|
||||
}
|
||||
if (!$firstType->isString()->yes()) {
|
||||
if (!$firstType instanceof StringType) {
|
||||
return \get_class($firstType) !== \get_class($secondType);
|
||||
}
|
||||
if (!$secondType instanceof ClassStringType) {
|
||||
@ -54,15 +58,15 @@ final class ScalarTypeComparator
|
||||
}
|
||||
private function isScalarType(Type $type) : bool
|
||||
{
|
||||
if ($type->isString()->yes()) {
|
||||
if ($type instanceof StringType) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isFloat()->yes()) {
|
||||
if ($type instanceof FloatType) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isInteger()->yes()) {
|
||||
if ($type instanceof IntegerType) {
|
||||
return \true;
|
||||
}
|
||||
return $type->isBoolean()->yes();
|
||||
return $type instanceof BooleanType;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer;
|
||||
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\UnionType;
|
||||
final class BoolUnionTypeAnalyzer
|
||||
@ -10,7 +11,7 @@ final class BoolUnionTypeAnalyzer
|
||||
public function isBoolUnionType(UnionType $unionType) : bool
|
||||
{
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
if (!$unionedType->isBoolean()->yes()) {
|
||||
if (!$unionedType instanceof BooleanType) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
@ -24,7 +25,7 @@ final class BoolUnionTypeAnalyzer
|
||||
$hasNullable = \true;
|
||||
continue;
|
||||
}
|
||||
if ($unionedType->isBoolean()->yes()) {
|
||||
if ($unionedType instanceof BooleanType) {
|
||||
continue;
|
||||
}
|
||||
return \false;
|
||||
|
@ -4,11 +4,15 @@ declare (strict_types=1);
|
||||
namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer;
|
||||
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\Constant\ConstantStringType;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\IterableType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis;
|
||||
@ -86,16 +90,16 @@ final class UnionTypeAnalyzer
|
||||
return \false;
|
||||
}
|
||||
foreach ($types as $type) {
|
||||
if ($type->isString()->yes() && !$type instanceof ConstantStringType) {
|
||||
if ($type instanceof StringType && !$type instanceof ConstantStringType) {
|
||||
continue;
|
||||
}
|
||||
if ($type->isFloat()->yes()) {
|
||||
if ($type instanceof FloatType) {
|
||||
continue;
|
||||
}
|
||||
if ($type->isInteger()->yes()) {
|
||||
if ($type instanceof IntegerType) {
|
||||
continue;
|
||||
}
|
||||
if ($type->isBoolean()->yes()) {
|
||||
if ($type instanceof BooleanType) {
|
||||
continue;
|
||||
}
|
||||
return \false;
|
||||
|
@ -14,6 +14,7 @@ use PHPStan\Type\ClassStringType;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
use PHPStan\Type\Constant\ConstantIntegerType;
|
||||
use PHPStan\Type\Generic\GenericClassStringType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NeverType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
@ -208,7 +209,7 @@ final class ArrayTypeMapper implements TypeMapperInterface
|
||||
}
|
||||
private function isIntegerKeyAndNonNestedArray(ArrayType $arrayType) : bool
|
||||
{
|
||||
if (!$arrayType->getKeyType()->isInteger()->yes()) {
|
||||
if (!$arrayType->getKeyType() instanceof IntegerType) {
|
||||
return \false;
|
||||
}
|
||||
return !$arrayType->getItemType() instanceof ArrayType;
|
||||
|
@ -204,7 +204,7 @@ final class UnionTypeMapper implements TypeMapperInterface
|
||||
private function mapNullabledType(Type $nullabledType, string $typeKind) : ?Node
|
||||
{
|
||||
// void cannot be nullable
|
||||
if ($nullabledType->isVoid()->yes()) {
|
||||
if ($nullabledType instanceof VoidType) {
|
||||
return null;
|
||||
}
|
||||
$nullabledTypeNode = $this->phpStanStaticTypeMapper->mapToPhpParserNode($nullabledType, $typeKind);
|
||||
|
@ -10,6 +10,8 @@ use PhpParser\Node\Scalar\String_;
|
||||
use PHPStan\Reflection\ParameterReflection;
|
||||
use PHPStan\Reflection\ParametersAcceptorSelector;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
@ -87,10 +89,10 @@ final class ExprParameterReflectionTypeCorrector
|
||||
}
|
||||
$clearParameterType = TypeCombinator::removeNull($parameterType);
|
||||
// correct type
|
||||
if ($clearParameterType->isInteger()->yes() && $item instanceof String_) {
|
||||
if ($clearParameterType instanceof IntegerType && $item instanceof String_) {
|
||||
return new LNumber((int) $item->value);
|
||||
}
|
||||
if ($clearParameterType->isBoolean()->yes() && $item instanceof String_) {
|
||||
if ($clearParameterType instanceof BooleanType && $item instanceof String_) {
|
||||
if (\strtolower($item->value) === 'true') {
|
||||
return $this->nodeFactory->createTrue();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use PHPStan\Reflection\FunctionVariantWithPhpDocs;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\FileSystem\FilePathHelper;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
@ -185,7 +186,7 @@ final class ClassMethodReturnTypeOverrideGuard
|
||||
return \true;
|
||||
}
|
||||
$childReturnType = $this->returnTypeInferer->inferFunctionLike($method);
|
||||
if ($returnType->isVoid()->yes() && !$childReturnType->isVoid()->yes()) {
|
||||
if ($returnType instanceof VoidType && !$childReturnType instanceof VoidType) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
@ -71,7 +72,7 @@ final class ExprBoolCaster
|
||||
return \false;
|
||||
}
|
||||
$exprType = $this->nodeTypeResolver->getType($expr);
|
||||
if ($exprType->isBoolean()->yes()) {
|
||||
if ($exprType instanceof BooleanType) {
|
||||
return \false;
|
||||
}
|
||||
return !$expr instanceof BinaryOp;
|
||||
|
@ -11,6 +11,7 @@ use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\NodeManipulator\BinaryOpManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -84,7 +85,7 @@ CODE_SAMPLE
|
||||
/** @var BooleanAnd|BooleanOr $booleanExpr */
|
||||
$booleanExpr = $expression->expr;
|
||||
$leftStaticType = $this->getType($booleanExpr->left);
|
||||
if (!$leftStaticType->isBoolean()->yes()) {
|
||||
if (!$leftStaticType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
$exprLeft = $booleanExpr->left instanceof BooleanNot ? $booleanExpr->left->expr : $booleanExpr->left;
|
||||
|
@ -7,6 +7,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -66,11 +67,11 @@ CODE_SAMPLE
|
||||
if ($node->expr instanceof Identical) {
|
||||
$identical = $node->expr;
|
||||
$leftType = $this->getType($identical->left);
|
||||
if (!$leftType->isBoolean()->yes()) {
|
||||
if (!$leftType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
$rightType = $this->getType($identical->right);
|
||||
if (!$rightType->isBoolean()->yes()) {
|
||||
if (!$rightType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
return new NotIdentical($identical->left, $identical->right);
|
||||
@ -80,11 +81,11 @@ CODE_SAMPLE
|
||||
private function processIdentical(Identical $identical) : ?NotIdentical
|
||||
{
|
||||
$leftType = $this->getType($identical->left);
|
||||
if (!$leftType->isBoolean()->yes()) {
|
||||
if (!$leftType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
$rightType = $this->getType($identical->right);
|
||||
if (!$rightType->isBoolean()->yes()) {
|
||||
if (!$rightType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if ($identical->left instanceof BooleanNot) {
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -54,11 +55,11 @@ CODE_SAMPLE
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$leftType = $this->getType($node->left);
|
||||
if ($leftType->isBoolean()->yes() && !$this->valueResolver->isTrueOrFalse($node->left)) {
|
||||
if ($leftType instanceof BooleanType && !$this->valueResolver->isTrueOrFalse($node->left)) {
|
||||
return $this->processBoolTypeToNotBool($node, $node->left, $node->right);
|
||||
}
|
||||
$rightType = $this->getType($node->right);
|
||||
if (!$rightType->isBoolean()->yes()) {
|
||||
if (!$rightType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
if ($this->valueResolver->isTrueOrFalse($node->right)) {
|
||||
@ -88,7 +89,7 @@ CODE_SAMPLE
|
||||
}
|
||||
$leftExprType = $this->getType($leftExpr);
|
||||
// keep as it is, readable enough
|
||||
if ($leftExpr instanceof Variable && $leftExprType->isBoolean()->yes()) {
|
||||
if ($leftExpr instanceof Variable && $leftExprType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
return new BooleanNot($leftExpr);
|
||||
|
@ -22,6 +22,9 @@ use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
@ -106,7 +109,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
$conditionStaticType = $this->getType($conditionNode);
|
||||
if ($conditionStaticType->isBoolean()->yes()) {
|
||||
if ($conditionStaticType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
$binaryOp = $this->resolveNewConditionNode($conditionNode, $isNegated);
|
||||
@ -143,10 +146,10 @@ CODE_SAMPLE
|
||||
return $this->resolveString($isNegated, $expr);
|
||||
}
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType->isInteger()->yes()) {
|
||||
if ($exprType instanceof IntegerType) {
|
||||
return $this->resolveInteger($isNegated, $expr);
|
||||
}
|
||||
if ($exprType->isFloat()->yes()) {
|
||||
if ($exprType instanceof FloatType) {
|
||||
return $this->resolveFloat($isNegated, $expr);
|
||||
}
|
||||
if ($this->nodeTypeResolver->isNullableTypeOfSpecificType($expr, ObjectType::class)) {
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\PhpParser\Node\AssignAndBinaryMap;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -93,7 +94,7 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
|
||||
private function processTrueIfExpressionWithFalseElseExpression(Expr $expr) : Expr
|
||||
{
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType->isBoolean()->yes()) {
|
||||
if ($exprType instanceof BooleanType) {
|
||||
return $expr;
|
||||
}
|
||||
return new Bool_($expr);
|
||||
@ -102,13 +103,13 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
|
||||
{
|
||||
if ($expr instanceof BooleanNot) {
|
||||
$negatedExprType = $this->getType($expr->expr);
|
||||
if ($negatedExprType->isBoolean()->yes()) {
|
||||
if ($negatedExprType instanceof BooleanType) {
|
||||
return $expr->expr;
|
||||
}
|
||||
return new Bool_($expr->expr);
|
||||
}
|
||||
$exprType = $this->getType($expr);
|
||||
if ($exprType->isBoolean()->yes()) {
|
||||
if ($exprType instanceof BooleanType) {
|
||||
return new BooleanNot($expr);
|
||||
}
|
||||
return new BooleanNot(new Bool_($expr));
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
@ -85,6 +86,6 @@ CODE_SAMPLE
|
||||
private function isBoolDocType(Property $property) : bool
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
return $phpDocInfo->getVarType()->isBoolean()->yes();
|
||||
return $phpDocInfo->getVarType() instanceof BooleanType;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Core\NodeManipulator\IfManipulator;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
@ -134,7 +135,7 @@ CODE_SAMPLE
|
||||
return \false;
|
||||
}
|
||||
$type = $this->nodeTypeResolver->getType($cond);
|
||||
if (!$type->isBoolean()->yes()) {
|
||||
if (!$type instanceof BooleanType) {
|
||||
return \false;
|
||||
}
|
||||
$nextNode = $ifWithOnlyReturns[0]->getAttribute(AttributeKey::NEXT_NODE);
|
||||
|
@ -7,6 +7,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -69,7 +70,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
$ifType = $this->getType($node->if);
|
||||
if (!$ifType->isBoolean()->yes()) {
|
||||
if (!$ifType instanceof BooleanType) {
|
||||
return null;
|
||||
}
|
||||
return new BooleanAnd($node->cond, $node->if);
|
||||
|
@ -35,6 +35,7 @@ use PHPStan\Reflection\ParametersAcceptorSelector;
|
||||
use PHPStan\Reflection\Php\PhpMethodReflection;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
@ -359,7 +360,7 @@ final class AnonymousFunctionFactory
|
||||
*/
|
||||
private function resolveStmts(FunctionVariantWithPhpDocs $functionVariantWithPhpDocs, $innerMethodCall) : array
|
||||
{
|
||||
if ($functionVariantWithPhpDocs->getReturnType()->isVoid()->yes()) {
|
||||
if ($functionVariantWithPhpDocs->getReturnType() instanceof VoidType) {
|
||||
return [new Expression($innerMethodCall)];
|
||||
}
|
||||
return [new Return_($innerMethodCall)];
|
||||
|
@ -12,6 +12,8 @@ use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\StringType;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -134,13 +136,16 @@ CODE_SAMPLE
|
||||
}
|
||||
private function isArrayKeyTypeAllowed(ArrayType $arrayType) : bool
|
||||
{
|
||||
if ($arrayType->getKeyType()->isInteger()->yes()) {
|
||||
return \true;
|
||||
$allowedKeyTypes = [IntegerType::class];
|
||||
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) {
|
||||
$allowedKeyTypes[] = StringType::class;
|
||||
}
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) {
|
||||
return \false;
|
||||
foreach ($allowedKeyTypes as $allowedKeyType) {
|
||||
if ($arrayType->getKeyType() instanceof $allowedKeyType) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return $arrayType->getKeyType()->isString()->yes();
|
||||
return \false;
|
||||
}
|
||||
private function resolveValue(Expr $expr) : Expr
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
@ -52,7 +53,7 @@ final class MbStrrposEncodingArgumentPositionRector extends AbstractRector imple
|
||||
return null;
|
||||
}
|
||||
$secondArgType = $this->getType($node->args[2]->value);
|
||||
if ($secondArgType->isInteger()->yes()) {
|
||||
if ($secondArgType instanceof IntegerType) {
|
||||
return null;
|
||||
}
|
||||
$node->args[3] = $node->args[2];
|
||||
|
@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Break_;
|
||||
use PhpParser\Node\Stmt\Case_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\Node\Stmt\Switch_;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
@ -45,7 +46,7 @@ final class SwitchAnalyzer
|
||||
}
|
||||
$uniqueTypes = $this->typeFactory->uniquateTypes($types);
|
||||
$countUniqueTypes = \count($uniqueTypes);
|
||||
if ($countUniqueTypes === 1 && $uniqueTypes[0]->isInteger()->yes()) {
|
||||
if ($countUniqueTypes === 1 && $uniqueTypes[0] instanceof IntegerType) {
|
||||
$switchCondType = $this->nodeTypeResolver->getType($expr);
|
||||
if (!$switchCondType instanceof MixedType && $switchCondType->isString()->maybe()) {
|
||||
return \true;
|
||||
|
@ -14,6 +14,8 @@ use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
@ -39,10 +41,10 @@ final class ExactCompareFactory
|
||||
if ($exprType->isString()->yes()) {
|
||||
return new Identical($expr, new String_(''));
|
||||
}
|
||||
if ($exprType->isInteger()->yes()) {
|
||||
if ($exprType instanceof IntegerType) {
|
||||
return new Identical($expr, new LNumber(0));
|
||||
}
|
||||
if ($exprType->isBoolean()->yes()) {
|
||||
if ($exprType instanceof BooleanType) {
|
||||
return new Identical($expr, $this->nodeFactory->createFalse());
|
||||
}
|
||||
if ($exprType->isArray()->yes()) {
|
||||
@ -64,7 +66,7 @@ final class ExactCompareFactory
|
||||
if ($exprType->isString()->yes()) {
|
||||
return new NotIdentical($expr, new String_(''));
|
||||
}
|
||||
if ($exprType->isInteger()->yes()) {
|
||||
if ($exprType instanceof IntegerType) {
|
||||
return new NotIdentical($expr, new LNumber(0));
|
||||
}
|
||||
if ($exprType->isArray()->yes()) {
|
||||
@ -81,7 +83,7 @@ final class ExactCompareFactory
|
||||
private function createFromUnionType(UnionType $unionType, Expr $expr, bool $treatAsNotEmpty)
|
||||
{
|
||||
$unionType = TypeCombinator::removeNull($unionType);
|
||||
if ($unionType->isBoolean()->yes()) {
|
||||
if ($unionType instanceof BooleanType) {
|
||||
return new Identical($expr, $this->nodeFactory->createTrue());
|
||||
}
|
||||
if ($unionType instanceof TypeWithClassName) {
|
||||
@ -170,7 +172,7 @@ final class ExactCompareFactory
|
||||
$compareExprs = $this->collectCompareExprs($unionType, $expr, $treatAsNonEmpty);
|
||||
return $this->createBooleanOr($compareExprs);
|
||||
}
|
||||
if ($unionType->isBoolean()->yes()) {
|
||||
if ($unionType instanceof BooleanType) {
|
||||
return new NotIdentical($expr, $this->nodeFactory->createTrue());
|
||||
}
|
||||
if ($unionType instanceof TypeWithClassName) {
|
||||
|
@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\Rector\ArrowFunction;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
@ -42,7 +43,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
$type = $this->getType($node->expr);
|
||||
if ($type->isVoid()->yes()) {
|
||||
if ($type instanceof VoidType) {
|
||||
return null;
|
||||
}
|
||||
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN);
|
||||
|
@ -19,6 +19,7 @@ use PhpParser\Node\UnionType as PhpParserUnionType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\UnionType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
@ -152,7 +153,7 @@ CODE_SAMPLE
|
||||
{
|
||||
$resolvedType = $this->nodeTypeResolver->getType($arrowFunction->expr);
|
||||
// void type is not accepted for arrow functions - https://www.php.net/manual/en/functions.arrow.php#125673
|
||||
if ($resolvedType->isVoid()->yes()) {
|
||||
if ($resolvedType instanceof VoidType) {
|
||||
return null;
|
||||
}
|
||||
$returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($resolvedType, TypeKind::RETURN);
|
||||
@ -170,7 +171,7 @@ CODE_SAMPLE
|
||||
$inferReturnType = $this->returnTypeInferer->inferFunctionLike($node);
|
||||
if ($inferReturnType instanceof UnionType) {
|
||||
foreach ($inferReturnType->getTypes() as $type) {
|
||||
if ($type->isVoid()->yes()) {
|
||||
if ($type instanceof VoidType) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
|
@ -118,13 +118,13 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
if ($type->isString()->yes() && !$type instanceof ConstantStringType) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isFloat()->yes()) {
|
||||
if ($type instanceof FloatType) {
|
||||
return \true;
|
||||
}
|
||||
if ($type->isInteger()->yes()) {
|
||||
if ($type instanceof IntegerType) {
|
||||
return \true;
|
||||
}
|
||||
return $type->isBoolean()->yes();
|
||||
return $type instanceof BooleanType;
|
||||
}
|
||||
private function resolveTypeFromScalar(Scalar $scalar) : ?\PHPStan\Type\Type
|
||||
{
|
||||
|
@ -16,11 +16,13 @@ use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\BenevolentUnionType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ThisType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
@ -144,7 +146,7 @@ final class ReturnTypeInferer
|
||||
*/
|
||||
private function resolveTypeWithVoidHandling($functionLike, Type $resolvedType) : Type
|
||||
{
|
||||
if ($resolvedType->isVoid()->yes()) {
|
||||
if ($resolvedType instanceof VoidType) {
|
||||
if ($functionLike instanceof ArrowFunction) {
|
||||
return new MixedType();
|
||||
}
|
||||
@ -161,7 +163,7 @@ final class ReturnTypeInferer
|
||||
}
|
||||
if ($resolvedType instanceof UnionType) {
|
||||
$benevolentUnionTypeIntegerType = $this->resolveBenevolentUnionTypeInteger($functionLike, $resolvedType);
|
||||
if ($benevolentUnionTypeIntegerType->isInteger()->yes()) {
|
||||
if ($benevolentUnionTypeIntegerType instanceof IntegerType) {
|
||||
return $benevolentUnionTypeIntegerType;
|
||||
}
|
||||
}
|
||||
@ -169,15 +171,16 @@ final class ReturnTypeInferer
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike
|
||||
* @return \PHPStan\Type\UnionType|\PHPStan\Type\IntegerType
|
||||
*/
|
||||
private function resolveBenevolentUnionTypeInteger($functionLike, UnionType $unionType) : Type
|
||||
private function resolveBenevolentUnionTypeInteger($functionLike, UnionType $unionType)
|
||||
{
|
||||
$types = $unionType->getTypes();
|
||||
$countTypes = \count($types);
|
||||
if ($countTypes !== 2) {
|
||||
return $unionType;
|
||||
}
|
||||
if (!($types[0]->isInteger()->yes() && $types[1]->isString()->yes())) {
|
||||
if (!($types[0] instanceof IntegerType && $types[1]->isString()->yes())) {
|
||||
return $unionType;
|
||||
}
|
||||
if (!$functionLike instanceof ArrowFunction) {
|
||||
|
@ -188,7 +188,7 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
|
||||
if ($resolvedType instanceof MixedType || $this->isArrayTypeMixed($resolvedType)) {
|
||||
$correctedType = $this->inferFromReturnedMethodCall($return, $functionLike);
|
||||
// override only if has some extra value
|
||||
if (!$correctedType instanceof MixedType && !$correctedType->isVoid()->yes()) {
|
||||
if (!$correctedType instanceof MixedType && !$correctedType instanceof VoidType) {
|
||||
return $correctedType;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'e66317aeb276bb0b544e7b4b55057c9dab5fbb73';
|
||||
public const PACKAGE_VERSION = 'dbb0e196a43d8c14a9de6abeef8fe081e95c51c2';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-04-08 12:28:02';
|
||||
public const RELEASE_DATE = '2023-04-08 20:19:33';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -42,6 +42,7 @@ use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
final class AssignAndBinaryMap
|
||||
{
|
||||
@ -96,7 +97,7 @@ final class AssignAndBinaryMap
|
||||
return new Bool_($expr);
|
||||
}
|
||||
$type = $scope->getType($expr);
|
||||
if ($type->isBoolean()->yes()) {
|
||||
if ($type instanceof BooleanType) {
|
||||
return $expr;
|
||||
}
|
||||
return new Bool_($expr);
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173::getLoader();
|
||||
return ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173
|
||||
class ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit827ced5e8bddbb7f983434d5761e2173', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5655b4feae432f84294783c771fa6ebd', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5655b4feae432f84294783c771fa6ebd::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit827ced5e8bddbb7f983434d5761e2173
|
||||
class ComposerStaticInit5655b4feae432f84294783c771fa6ebd
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3135,9 +3135,9 @@ class ComposerStaticInit827ced5e8bddbb7f983434d5761e2173
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit827ced5e8bddbb7f983434d5761e2173::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5655b4feae432f84294783c771fa6ebd::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user