Skip to content

Commit

Permalink
Revert all is* changes (#3584)
Browse files Browse the repository at this point in the history
* Revert fix cs (#3579)

This reverts commit e66317a.

* Revert Use isInteger() (#3571)

This reverts commit 59cdfc8.

* Revert Use isBoolean() (#3570)

This reverts commit 437cc5a.

* Revert Use isVoid() (#3574)

This reverts commit 7611dcb.

* Revert Use isString() (#3573)

This reverts commit aa73118.

* Revert Use isFloat() (#3572)

This reverts commit 46301c1.

* Revert Improve ArraySpreadInsteadOfArrayMergeRector (#3568)

This reverts commit 073f2d6.
  • Loading branch information
samsonasik committed Apr 8, 2023
1 parent e66317a commit dbb0e19
Show file tree
Hide file tree
Showing 35 changed files with 136 additions and 107 deletions.
5 changes: 1 addition & 4 deletions packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,7 @@ public function getAnnotationClassNames(): array
public function getGenericTagClassNames(): array
{
/** @var GenericTagValueNode[] $genericTagValueNodes */
$genericTagValueNodes = $this->phpDocNodeByTypeFinder->findByType(
$this->phpDocNode,
GenericTagValueNode::class
);
$genericTagValueNodes = $this->phpDocNodeByTypeFinder->findByType($this->phpDocNode, GenericTagValueNode::class);

$resolvedClasses = [];

Expand Down
7 changes: 4 additions & 3 deletions packages/NodeTypeResolver/NodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
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;
Expand Down Expand Up @@ -238,12 +240,11 @@ public function getNativeType(Expr $expr): Type
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;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/NodeTypeResolver/PHPStan/Type/StaticTypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
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;
Expand Down Expand Up @@ -61,7 +64,7 @@ private function isScalarType(Type $type): bool
return true;
}

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

Expand All @@ -70,12 +73,11 @@ private function isScalarType(Type $type): bool
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
Expand Down
28 changes: 15 additions & 13 deletions packages/NodeTypeResolver/TypeComparator/ScalarTypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

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;

/**
Expand All @@ -14,28 +18,27 @@ 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 = $firstType::class;
$secondTypeClass = $secondType::class;

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;
}

/**
Expand All @@ -52,11 +55,11 @@ public function areDifferentScalarTypes(Type $firstType, Type $secondType): bool
}

// 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 $firstType::class !== $secondType::class;
}

Expand All @@ -69,19 +72,18 @@ public function areDifferentScalarTypes(Type $firstType, Type $secondType): bool

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer;

use PHPStan\Type\BooleanType;
use PHPStan\Type\NullType;
use PHPStan\Type\UnionType;

Expand All @@ -12,7 +13,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;
}
}
Expand All @@ -29,7 +30,7 @@ public function isNullableBoolUnionType(UnionType $unionType): bool
continue;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
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;
Expand Down Expand Up @@ -106,19 +110,19 @@ public function isScalar(UnionType $unionType): bool
}

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -247,7 +248,7 @@ private function isPairClassTooDetailed(Type $itemType): bool

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function resolveNullableType(NullableType $nullableType): null|NullableT
private function mapNullabledType(Type $nullabledType, string $typeKind): ?Node
{
// void cannot be nullable
if ($nullabledType->isVoid()->yes()) {
if ($nullabledType instanceof VoidType) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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;
Expand Down Expand Up @@ -90,11 +92,11 @@ private function correctItemByParameterReflection(
$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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -175,7 +176,7 @@ private function shouldSkipHasChildHasReturnType(array $childrenClassReflections
}

$childReturnType = $this->returnTypeInferer->inferFunctionLike($method);
if ($returnType->isVoid()->yes() && ! $childReturnType->isVoid()->yes()) {
if ($returnType instanceof VoidType && ! $childReturnType instanceof VoidType) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class IntegerKeys
{
public function run()
{
$iter1 = [0 => 'two', 3 => 'four'];
$iter2 = [5 => 'six', 7 => 'eight'];
$iter1 = [0 => 'two'];
$iter2 = [1 => 'four'];

return array_merge($iter1, $iter2);
}
Expand All @@ -23,8 +23,8 @@ class IntegerKeys
{
public function run()
{
$iter1 = [0 => 'two', 3 => 'four'];
$iter2 = [5 => 'six', 7 => 'eight'];
$iter1 = [0 => 'two'];
$iter2 = [1 => 'four'];

return [...$iter1, ...$iter2];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class SkipStringKeys
{
public function run()
{
$iter1 = ['one' => 'two', 'three' => 'four'];
$iter2 = ['five' => 'six', 'seven' => 'eight'];
$iter1 = ['one' => 'two'];
$iter2 = ['three' => 'four'];

return array_merge($iter1, $iter2);
}

public function go()
{
$iter1 = [1 => 'two', 3 => 'four'];
$iter2 = ['five' => 'six', 'seven' => 'eight'];
$iter1 = [1 => 'two'];
$iter2 = ['three' => 'four'];

return array_merge($iter1, $iter2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class IntegerKeys
{
public function run()
{
$iter1 = [0 => 'two', 3 => 'four'];
$iter2 = [5 => 'six', 7 => 'eight'];
$iter1 = [0 => 'two'];
$iter2 = [1 => 'four'];

return array_merge($iter1, $iter2);
}
Expand All @@ -23,8 +23,8 @@ class IntegerKeys
{
public function run()
{
$iter1 = [0 => 'two', 3 => 'four'];
$iter2 = [5 => 'six', 7 => 'eight'];
$iter1 = [0 => 'two'];
$iter2 = [1 => 'four'];

return [...$iter1, ...$iter2];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class StringKeys
{
public function run()
{
$iter1 = ['one' => 'two', 'three' => 'four'];
$iter2 = ['five' => 'six', 'seven' => 'eight'];
$iter1 = ['one' => 'two'];
$iter2 = ['three' => 'four'];

return array_merge($iter1, $iter2);
}

public function go()
{
$iter1 = [1 => 'two', 3 => 'four'];
$iter2 = ['five' => 'six', 'seven' => 'eight'];
$iter1 = [1 => 'two'];
$iter2 = ['three' => 'four'];

return array_merge($iter1, $iter2);
}
Expand All @@ -30,16 +30,16 @@ class StringKeys
{
public function run()
{
$iter1 = ['one' => 'two', 'three' => 'four'];
$iter2 = ['five' => 'six', 'seven' => 'eight'];
$iter1 = ['one' => 'two'];
$iter2 = ['three' => 'four'];

return [...$iter1, ...$iter2];
}

public function go()
{
$iter1 = [1 => 'two', 3 => 'four'];
$iter2 = ['five' => 'six', 'seven' => 'eight'];
$iter1 = [1 => 'two'];
$iter2 = ['three' => 'four'];

return [...$iter1, ...$iter2];
}
Expand Down
Loading

0 comments on commit dbb0e19

Please sign in to comment.