Skip to content

Commit

Permalink
make use of ComplexType
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 14, 2021
1 parent 6d176c7 commit b161a74
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
6 changes: 2 additions & 4 deletions packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
namespace Rector\FamilyTree\Reflection;

use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\IntersectionType;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\UnionType as PhpParserUnionType;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
Expand Down Expand Up @@ -69,7 +67,7 @@ public function getPossibleUnionPropertyType(
Property $property,
Type $varType,
?Scope $scope,
Name | NullableType | PhpParserUnionType | IntersectionType| null $propertyTypeNode
Name | ComplexType | null $propertyTypeNode
): PropertyType {
if ($varType instanceof UnionType) {
return new PropertyType($varType, $propertyTypeNode);
Expand Down
10 changes: 3 additions & 7 deletions packages/PHPStanStaticTypeMapper/PHPStanStaticTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace Rector\PHPStanStaticTypeMapper;

use PhpParser\Node\IntersectionType;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\UnionType;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
Expand Down Expand Up @@ -48,10 +46,8 @@ public function mapToPHPStanPhpDocTypeNode(Type $type, TypeKind $typeKind): Type
throw new NotImplementedYetException(__METHOD__ . ' for ' . $type::class);
}

public function mapToPhpParserNode(
Type $type,
TypeKind $typeKind
): Name | NullableType | UnionType | IntersectionType | null {
public function mapToPhpParserNode(Type $type, TypeKind $typeKind): Name | ComplexType | null
{
foreach ($this->typeMappers as $typeMapper) {
if (! is_a($type, $typeMapper->getNodeClass(), true)) {
continue;
Expand Down
6 changes: 2 additions & 4 deletions packages/StaticTypeMapper/StaticTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
namespace Rector\StaticTypeMapper;

use PhpParser\Node;
use PhpParser\Node\IntersectionType;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\UnionType as PhpParserUnionType;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
Expand Down Expand Up @@ -48,7 +46,7 @@ public function mapPHPStanTypeToPHPStanPhpDocTypeNode(Type $phpStanType, TypeKin
}

/**
* @return Name|NullableType|PhpParserUnionType|IntersectionType|null
* @return Name|ComplexType|null
*/
public function mapPHPStanTypeToPhpParserNode(Type $phpStanType, TypeKind $typeKind): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function refactor(Node $node): ?Node
}

// Make it nullable?
if ($node->returnType instanceof NullableType && ! $parentReturnTypeNode instanceof NullableType && ! $parentReturnTypeNode instanceof UnionType && ! $parentReturnTypeNode instanceof Node\IntersectionType) {
if ($node->returnType instanceof NullableType && ! $parentReturnTypeNode instanceof ComplexType) {
$parentReturnTypeNode = new NullableType($parentReturnTypeNode);
}

Expand Down
4 changes: 2 additions & 2 deletions rules/Php74/Rector/Property/TypedPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\Node\UnionType as PhpParserUnionType;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\MixedType;
Expand Down Expand Up @@ -166,6 +165,7 @@ public function refactor(Node $node): ?Node
}

$scope = $node->getAttribute(AttributeKey::SCOPE);

$propertyType = $this->familyRelationsAnalyzer->getPossibleUnionPropertyType(
$node,
$varType,
Expand Down Expand Up @@ -200,7 +200,7 @@ public function provideMinPhpVersion(): int
}

private function isNullOrNonClassLikeTypeOrMixedOrVendorLockedIn(
Name | NullableType | PhpParserUnionType | Node\IntersectionType | null $node,
Name | ComplexType | null $node,
Property $property,
Type $type
): bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use PhpParser\Node\FunctionLike;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\UnionType;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function provideMinPhpVersion(): int
}

/**
* @return Node\Name|UnionType|NullableType|Node\IntersectionType|null
* @return Node\Name|Node\ComplexType|null
*/
private function matchPropertySingleTypeNode(PropertyFetch $propertyFetch): ?Node
{
Expand All @@ -145,7 +145,7 @@ private function matchPropertySingleTypeNode(PropertyFetch $propertyFetch): ?Nod
return null;
}

if ($propertyType instanceof \PHPStan\Type\UnionType) {
if ($propertyType instanceof UnionType) {
return null;
}

Expand Down

0 comments on commit b161a74

Please sign in to comment.