Skip to content
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
59 changes: 29 additions & 30 deletions config/set/cakephp/cakephp40.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,67 +69,66 @@ services:
Cake\View\Helper:
initialize: 'void'

Rector\Rector\Typehint\ParentTypehintedArgumentRector:
$typehintForArgumentByMethodAndClass:
Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector:
$typehintForParameterByMethodByClass:
Cake\ORM\Behavior:
beforeFind:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
buildValidator:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
buildRules:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeRules:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterRules:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeSave:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterSave:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeDelete:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterDelete:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
Cake\ORM\Table:
beforeFind:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
buildValidator:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
buildRules:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeRules:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterRules:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeSave:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterSave:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeDelete:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterDelete:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
Cake\Controller\Controller:
beforeFilter:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
afterFilter:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeRender:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeRedirect:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
Cake\Controller\Component:
shutdown:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
startup:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeFilter:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeRender:
$event: 'Cake\Event\EventInterface'
0: 'Cake\Event\EventInterface'
beforeRedirect:
$event: 'Cake\Event\EventInterface'

0: 'Cake\Event\EventInterface'

Rector\CakePHP\Rector\MethodCall\RenameMethodCallBasedOnParameterRector:
$methodNamesByTypes:
Expand Down
8 changes: 4 additions & 4 deletions config/set/doctrine/doctrine25.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
services:
Rector\Rector\Typehint\ParentTypehintedArgumentRector:
$typehintForArgumentByMethodAndClass:
Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector:
$typehintForParameterByMethodByClass:
Doctrine\ORM\Mapping\ClassMetadataFactory:
setEntityManager:
em: 'Doctrine\ORM\EntityManagerInterface'
0: 'Doctrine\ORM\EntityManagerInterface'
Doctrine\ORM\Tools\DebugUnitOfWorkListener:
dumpIdentityMap:
em: 'Doctrine\ORM\EntityManagerInterface'
0: 'Doctrine\ORM\EntityManagerInterface'

Rector\Rector\Argument\ArgumentRemoverRector:
$positionsByMethodNameByClassType:
Expand Down
6 changes: 3 additions & 3 deletions config/set/phpunit/phpunit80.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ imports:

services:
# https://github.com/rectorphp/rector/issues/1024
Rector\Rector\Typehint\ParentTypehintedArgumentRector:
$typehintForArgumentByMethodAndClass:
Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector:
$typehintForParameterByMethodByClass:
PHPUnit\Framework\TestCase:
__construct:
dataName: '' # no type
2: '' # no type, $dataName

Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsRector: ~
Rector\PHPUnit\Rector\MethodCall\SpecificAssertInternalTypeRector: ~
Expand Down
6 changes: 3 additions & 3 deletions config/set/sylius/sylius10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ services:
'Sylius\Component\Taxonomy\Model\TaxonInterface':
'getParents ': 'getAncestors'

Rector\Rector\Typehint\ParentTypehintedArgumentRector:
$typehintForArgumentByMethodAndClass:
Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector:
$typehintForParameterByMethodByClass:
Sylius\Bundle\CoreBundle\Context\SessionAndChannelBasedCartContext:
__construct:
$cartStorage: 'Sylius\Component\Core\Storage\CartStorageInterface'
0: 'Sylius\Component\Core\Storage\CartStorageInterface'

Rector\Rector\Argument\ArgumentAdderRector:
$positionWithDefaultValueByMethodNamesByClassTypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function process(string $name)
}
}
PHP

, [
'$typehintForParameterByMethodByClass' => [
'SomeClass' => [
Expand Down Expand Up @@ -141,6 +140,18 @@ private function shouldSkip(ClassMethod $classMethod): bool
return ! (bool) $class->extends;
}

private function refactorClassMethodWithTypehintByParameterPosition(Node $node, $typehintByParameterPosition): void
{
foreach ($typehintByParameterPosition as $parameterPosition => $type) {
if (! isset($node->params[$parameterPosition])) {
continue;
}

$parameter = $node->params[$parameterPosition];
$this->refactorParameter($parameter, $type);
}
}

private function refactorParameter(Param $param, string $newType): void
{
// already set → no change
Expand All @@ -161,16 +172,4 @@ private function refactorParameter(Param $param, string $newType): void

$param->type = $returnTypeNode;
}

private function refactorClassMethodWithTypehintByParameterPosition(Node $node, $typehintByParameterPosition): void
{
foreach ($typehintByParameterPosition as $parameterPosition => $type) {
if (! isset($node->params[$parameterPosition])) {
continue;
}

$parameter = $node->params[$parameterPosition];
$this->refactorParameter($parameter, $type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ClassMetadataFactory;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ParserInterface;

final class AddParamTypeDeclarationRectorTest extends AbstractRectorTestCase
{
Expand All @@ -33,6 +35,16 @@ protected function getRectorsWithConfiguration(): array
0 => 'string',
],
],
ParserInterface::class => [
'parse' => [
0 => 'string',
],
],
ClassMetadataFactory::class => [
'setEntityManager' => [
0 => 'Doctrine\ORM\EntityManagerInterface',
],
],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Fixture;

use Doctrine\ORM\EntityManager;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ClassMetadataFactory;

class MyMetadataFactory extends ClassMetadataFactory
{
public function setEntityManager(EntityManager $emanager)
{
$this->em = $emanager;
}
}

?>
-----
<?php

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Fixture;

use Doctrine\ORM\EntityManager;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ClassMetadataFactory;

class MyMetadataFactory extends ClassMetadataFactory
{
public function setEntityManager(\Doctrine\ORM\EntityManagerInterface $emanager)
{
$this->em = $emanager;
}
}

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

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Fixture;

use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ParserInterface;

class SomeClassImplementingParserInterface implements ParserInterface
{
public function parse($code, \PhpParser\ErrorHandler $errorHandler = null)
{
}
}

?>
-----
<?php

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Fixture;

use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ParserInterface;

class SomeClassImplementingParserInterface implements ParserInterface
{
public function parse(string $code, \PhpParser\ErrorHandler $errorHandler = null)
{
}
}

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

declare(strict_types=1);

namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source;

class ClassMetadataFactory
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\Tests\Rector\Typehint\ParentTypehintedArgumentRector\Source;
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source;

interface ParserInterface
{
Expand Down
Loading