Merge pull request #1015 from rectorphp/rename

Rename `ReturnTypehintRector` to `AddReturnTypeDeclarationRector`
This commit is contained in:
Tomáš Votruba 2019-02-04 10:11:16 -08:00 committed by GitHub
commit 3106549aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 130 additions and 68 deletions

View File

@ -7,7 +7,7 @@ services:
'PHPUnit_Framework_MockObject_MockObject': 'PHPUnit\Framework\MockObject\MockObject'
Rector\PHPUnit\Rector\MethodCall\AssertEqualsParameterToSpecificMethodsTypeRector: ~
Rector\Rector\Typehint\ReturnTypehintRector:
Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
PHPUnit\Framework\TestCase:
setUpBeforeClass: 'void'
setUp: 'void'

View File

@ -32,7 +32,7 @@ services:
2:
__unknown__: false
Rector\Rector\Typehint\ReturnTypehintRector:
Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
Sylius\Component\Order\Model\OrderInterface:
getAdjustmentsRecursively:
'array': 'Doctrine\Common\Collections\Collection'

View File

@ -1,6 +1,6 @@
# source: https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.0.md#upgrade-from-101-to-102
services:
Rector\Rector\Typehint\ReturnTypehintRector:
Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
Sylius\Bundle\AdminApiBundle\Model\ClientManager:
findClientByPublicId: '?Sylius\Bundle\AdminApiBundle\Model\ClientInterface'

View File

@ -1,6 +1,6 @@
# source: https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.0.md#upgrade-from-108-to-109
services:
Rector\Rector\Typehint\ReturnTypehintRector:
Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
Sylius\Bundle\CoreBundle\Templating\Helper\VariantResolverHelper:
resolveVariant: '?Sylius\Component\Product\Model\ProductVariantInterface'

View File

@ -67,7 +67,7 @@ services:
Symfony\Component\Form\AbstractTypeExtension:
getExtendedType: 'getExtendedTypes'
Rector\Rector\Typehint\ReturnTypehintRector:
Rector\Php\Rector\FunctionLike\ReturnTypeDeclarationRector:
Symfony\Component\Form\AbstractTypeExtension:
getExtendedTypes: 'iterable'

View File

@ -3042,6 +3042,31 @@ services:
<br>
### `AddReturnTypeDeclarationRector`
- class: `Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector`
Changes defined return typehint of method and class.
```yaml
services:
Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
SomeClass:
getData: array
```
```diff
class SomeClass
{
- public getData();
+ public getData(): array;
}
```
<br>
### `MethodCallToAnotherMethodCallWithArgumentsRector`
- class: `Rector\Rector\MethodCall\MethodCallToAnotherMethodCallWithArgumentsRector`
@ -3315,31 +3340,6 @@ services:
<br>
### `ReturnTypehintRector`
- class: `Rector\Rector\Typehint\ReturnTypehintRector`
Changes defined return typehint of method and class.
```yaml
services:
Rector\Rector\Typehint\ReturnTypehintRector:
SomeClass:
getData: array
```
```diff
class SomeClass
{
- public getData();
+ public getData(): array;
}
```
<br>
### `ParentTypehintedArgumentRector`
- class: `Rector\Rector\Typehint\ParentTypehintedArgumentRector`

View File

@ -29,6 +29,7 @@ final class TypeAnalyzer
'int',
'self',
'parent',
'void',
],
true
);

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
namespace Rector\Rector\Typehint;
namespace Rector\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
@ -9,7 +9,7 @@ use Rector\Rector\AbstractRector;
use Rector\RectorDefinition\ConfiguredCodeSample;
use Rector\RectorDefinition\RectorDefinition;
final class ReturnTypehintRector extends AbstractRector
final class AddReturnTypeDeclarationRector extends AbstractRector
{
/**
* class => [

View File

@ -0,0 +1,38 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
final class AddReturnTypeDeclarationRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc', __DIR__ . '/Fixture/extended_parent.php.inc']);
}
protected function getRectorClass(): string
{
return AddReturnTypeDeclarationRector::class;
}
/**
* @return mixed[]
*/
protected function getRectorConfiguration(): array
{
return [
'Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture\SomeClass' => [
'parse' => 'array',
'resolve' => 'SomeType',
'nullable' => '?SomeType',
'clear' => '',
],
PHPUnitTestCase::class => [
'tearDown' => 'void',
],
];
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace {
use Rector\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
abstract class Abstract_Test_Case extends PHPUnitTestCase
{
protected function tearDown()
{
}
}
}
namespace Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture
{
final class FinalTestCase extends \Abstract_Test_Case
{
public function tearDown()
{
}
}
}
?>
-----
<?php
namespace {
use Rector\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
abstract class Abstract_Test_Case extends PHPUnitTestCase
{
protected function tearDown(): void
{
}
}
}
namespace Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture
{
final class FinalTestCase extends \Abstract_Test_Case
{
public function tearDown(): void
{
}
}
}
?>

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Tests\Rector\Typehint\ReturnTypehintRector\Fixture;
namespace Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;
class SomeClass
{
@ -25,7 +25,7 @@ class SomeClass
-----
<?php
namespace Rector\Tests\Rector\Typehint\ReturnTypehintRector\Fixture;
namespace Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;
class SomeClass
{

View File

@ -0,0 +1,8 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source;
abstract class PHPUnitTestCase
{
}

View File

@ -1,34 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\Typehint\ReturnTypehintRector;
use Rector\Rector\Typehint\ReturnTypehintRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class ReturnTypehintRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc']);
}
protected function getRectorClass(): string
{
return ReturnTypehintRector::class;
}
/**
* @return mixed[]
*/
protected function getRectorConfiguration(): array
{
return [
'Rector\Tests\Rector\Typehint\ReturnTypehintRector\Fixture\SomeClass' => [
'parse' => 'array',
'resolve' => 'SomeType',
'nullable' => '?SomeType',
'clear' => '',
],
];
}
}