[Type Declaration] Fix unwrapping of multiple union types (#4043)

This commit is contained in:
dobryy 2020-08-27 21:05:00 +02:00 committed by GitHub
parent dffcae0c82
commit 5b4797af85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 1 deletions

View File

@ -92,7 +92,7 @@ final class TypeFactory
$unwrappedTypes = [];
foreach ($types as $key => $type) {
if ($type instanceof UnionType) {
$unwrappedTypes = $type->getTypes();
$unwrappedTypes = array_merge($unwrappedTypes, $type->getTypes());
unset($types[$key]);
}

View File

@ -19,11 +19,24 @@ final class AddArrayReturnDocTypeRectorTest extends AbstractRectorTestCase
$this->doTestFileInfo($fileInfo);
}
/**
* @dataProvider provideDataRectorUseCases()
*/
public function testRectorUseCases(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
public function provideDataRectorUseCases(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/RectorUseCasesFixture');
}
protected function getRectorClass(): string
{
return AddArrayReturnDocTypeRector::class;

View File

@ -0,0 +1,70 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\RectorUseCasesFixture;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
class CallReflectionResolverFixture
{
public function resolveCall(Node $node)
{
if ($node instanceof FuncCall) {
return $this->resolveFunctionCall($node);
}
return $this->resolveMethodCall($node);
}
/**
* @return FunctionReflection|MethodReflection|null
*/
private function resolveFunctionCall(FuncCall $funcCall)
{
}
private function resolveMethodCall(Node $node): ?MethodReflection
{
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\RectorUseCasesFixture;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
class CallReflectionResolverFixture
{
/**
* @return \PHPStan\Reflection\FunctionReflection|\PHPStan\Reflection\MethodReflection|null
*/
public function resolveCall(Node $node)
{
if ($node instanceof FuncCall) {
return $this->resolveFunctionCall($node);
}
return $this->resolveMethodCall($node);
}
/**
* @return FunctionReflection|MethodReflection|null
*/
private function resolveFunctionCall(FuncCall $funcCall)
{
}
private function resolveMethodCall(Node $node): ?MethodReflection
{
}
}
?>