mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-13 20:12:07 +01:00
fix type resolving
This commit is contained in:
parent
180c08b39b
commit
9c6d57aa79
@ -6,6 +6,7 @@ use phpDocumentor\Reflection\Type;
|
||||
use phpDocumentor\Reflection\Types\Object_;
|
||||
use phpDocumentor\Reflection\Types\Self_;
|
||||
use phpDocumentor\Reflection\Types\Static_;
|
||||
use phpDocumentor\Reflection\Types\This;
|
||||
use Roave\BetterReflection\Reflection\ReflectionMethod;
|
||||
use Throwable;
|
||||
|
||||
@ -94,7 +95,7 @@ final class MethodReflector
|
||||
$types[] = ltrim((string) $returnType->getFqsen(), '\\');
|
||||
}
|
||||
|
||||
if ($returnType instanceof Static_ || $returnType instanceof Self_) {
|
||||
if ($returnType instanceof Static_ || $returnType instanceof Self_ || $returnType instanceof This) {
|
||||
$types[] = $class;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\MethodCallTypeResolver\ChainSource;
|
||||
|
||||
$tableStyle = new ChainTableStyle();
|
||||
$tableStyle->setCrossingChar(' ')
|
||||
->setHorizontalBorderChar('<fg=magenta>-</>');
|
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\MethodCallTypeResolver\ChainSource;
|
||||
|
||||
class ChainTableStyle
|
||||
{
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setCrossingChar($value)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setHorizontalBorderChar($value)
|
||||
{}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\MethodCallTypeResolver;
|
||||
|
||||
use Iterator;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\AbstractNodeTypeResolverTest;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\MethodCallTypeResolver\ChainSource\ChainTableStyle;
|
||||
|
||||
/**
|
||||
* @covers \Rector\NodeTypeResolver\PerNodeTypeResolver\MethodCallTypeResolver
|
||||
*/
|
||||
final class ChainTest extends AbstractNodeTypeResolverTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
* @param string[] $expectedTypes
|
||||
*/
|
||||
public function test(string $file, int $nodePosition, string $methodName, array $expectedTypes): void
|
||||
{
|
||||
/** @var MethodCall[] $methodCallNodes */
|
||||
$methodCallNodes = $this->getNodesForFileOfType($file, MethodCall::class);
|
||||
|
||||
$methodCallNode = $methodCallNodes[$nodePosition];
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNode->name;
|
||||
$this->assertSame($methodName, $identifierNode->toString());
|
||||
|
||||
$this->assertSame($expectedTypes, $this->nodeTypeResolver->resolve($methodCallNode->var));
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [
|
||||
__DIR__ . '/ChainSource/ChainMethodCall.php',
|
||||
0,
|
||||
'setHorizontalBorderChar',
|
||||
[ChainTableStyle::class],
|
||||
];
|
||||
|
||||
yield [__DIR__ . '/ChainSource/ChainMethodCall.php', 1, 'setCrossingChar', [ChainTableStyle::class]];
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Dynamic\MethodNameReplacerRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Rector\Rector\Dynamic\MethodNameReplacerRector
|
||||
*/
|
||||
final class ChainTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideWrongToFixedFiles()
|
||||
*/
|
||||
public function test(string $wrong, string $fixed): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent($wrong, $fixed);
|
||||
}
|
||||
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/wrong/wrong8.php.inc', __DIR__ . '/correct/correct8.php.inc'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
{
|
||||
return __DIR__ . '/chain-config.yml';
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
services:
|
||||
Rector\Rector\Dynamic\MethodNameReplacerRector:
|
||||
$perClassOldToNewMethods:
|
||||
# Console
|
||||
'Symfony\Component\Console\Helper\TableStyle':
|
||||
'oldMethod': 'newMethod'
|
||||
'anotherOldMethod': 'anotherNewMethod'
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
|
||||
$tableStyle = new TableStyle();
|
||||
$tableStyle->newMethod(' ')
|
||||
->anotherNewMethod('<fg=magenta>-</>');
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
|
||||
$tableStyle = new TableStyle();
|
||||
$tableStyle->oldMethod(' ')
|
||||
->anotherOldMethod('<fg=magenta>-</>');
|
Loading…
x
Reference in New Issue
Block a user