Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ReturnTypehintRector to AddReturnTypeDeclarationRector #1015

Merged
merged 4 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/level/phpunit/phpunit80.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion config/level/sylius/sylius10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion config/level/sylius/sylius102.yaml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion config/level/sylius/sylius109.yaml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion config/level/symfony/symfony42.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
50 changes: 25 additions & 25 deletions docs/AllRectorsOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/Php/TypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function isPhpReservedType(string $type): bool
'int',
'self',
'parent',
'void',
],
true
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +9,7 @@
use Rector\RectorDefinition\ConfiguredCodeSample;
use Rector\RectorDefinition\RectorDefinition;

final class ReturnTypehintRector extends AbstractRector
final class AddReturnTypeDeclarationRector extends AbstractRector
{
/**
* class => [
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
],
];
}
}
Original file line number Diff line number Diff line change
@@ -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
{
}
}
}

?>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Rector\Typehint\ReturnTypehintRector\Fixture;
namespace Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;

class SomeClass
{
Expand All @@ -25,7 +25,7 @@ class SomeClass
-----
<?php

namespace Rector\Tests\Rector\Typehint\ReturnTypehintRector\Fixture;
namespace Rector\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;

class SomeClass
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Rector\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source;

abstract class PHPUnitTestCase
{

}

This file was deleted.