Skip to content

Commit

Permalink
[PHPStanStaticTypeMapper] Remove BoolUnionTypeAnalyzer on UnionTypeMa…
Browse files Browse the repository at this point in the history
…pper (#5141)
  • Loading branch information
samsonasik committed Oct 8, 2023
1 parent c07a44f commit e83c7ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.

This file was deleted.

11 changes: 2 additions & 9 deletions packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\BoolUnionTypeAnalyzer;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeCommonTypeNarrower;
use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis;
Expand All @@ -52,7 +51,6 @@ public function __construct(
private readonly DoctrineTypeAnalyzer $doctrineTypeAnalyzer,
private readonly PhpVersionProvider $phpVersionProvider,
private readonly UnionTypeAnalyzer $unionTypeAnalyzer,
private readonly BoolUnionTypeAnalyzer $boolUnionTypeAnalyzer,
private readonly UnionTypeCommonTypeNarrower $unionTypeCommonTypeNarrower,
private readonly NodeNameResolver $nodeNameResolver,
private readonly TypeFactory $typeFactory
Expand Down Expand Up @@ -312,7 +310,7 @@ private function matchTypeForUnionedObjectTypes(UnionType $unionType, string $ty
}

if ($phpParserUnionType instanceof PhpParserUnionType) {
return $this->narrowBoolType($unionType, $phpParserUnionType, $typeKind);
return $this->resolveUnionTypeNode($unionType, $phpParserUnionType, $typeKind);
}

$compatibleObjectTypeNode = $this->processResolveCompatibleObjectCandidates($unionType);
Expand Down Expand Up @@ -491,16 +489,11 @@ private function narrowIntegerType(UnionType $unionType): ?Identifier
/**
* @param TypeKind::* $typeKind
*/
private function narrowBoolType(
private function resolveUnionTypeNode(
UnionType $unionType,
PhpParserUnionType $phpParserUnionType,
string $typeKind
): PhpParserUnionType|null|Identifier|Name|ComplexType {
// maybe all one type
if ($this->boolUnionTypeAnalyzer->isBoolUnionType($unionType)) {
return new Identifier('bool');
}

if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture;

function getThruthyCheck($number, $number2)
{
return $number ? false : (bool) $number2;
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture;

function getThruthyCheck($number, $number2): bool
{
return $number ? false : (bool) $number2;
}

?>

0 comments on commit e83c7ef

Please sign in to comment.