Merge pull request #3551 from rectorphp/inter-form

skip Form factories too
This commit is contained in:
Tomas Votruba 2020-06-18 17:00:02 +02:00 committed by GitHub
commit cf663c4fe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 9 deletions

View File

@ -82,7 +82,7 @@ PHP
throw new ShouldNotHappenException(); throw new ShouldNotHappenException();
} }
if ($this->isNetteControlFactory($oldInterfaceName)) { if ($this->isNetteMagicGeneratedFactory($oldInterfaceName)) {
return; return;
} }
@ -118,7 +118,10 @@ PHP
return $classLikeName; return $classLikeName;
} }
private function isNetteControlFactory(string $interfaceName): bool /**
* @see https://doc.nette.org/en/3.0/components#toc-components-with-dependencies
*/
private function isNetteMagicGeneratedFactory(string $interfaceName): bool
{ {
$reflectionClass = new ReflectionClass($interfaceName); $reflectionClass = new ReflectionClass($interfaceName);
foreach ($reflectionClass->getMethods() as $methodReflection) { foreach ($reflectionClass->getMethods() as $methodReflection) {
@ -126,11 +129,15 @@ PHP
continue; continue;
} }
if (! is_a((string) $methodReflection->getReturnType(), 'Nette\Application\UI\Control', true)) { $returnType = (string) $methodReflection->getReturnType();
continue;
if (is_a($returnType, 'Nette\Application\UI\Control', true)) {
return true;
} }
return true; if (is_a($returnType, 'Nette\Application\UI\Form', true)) {
return true;
}
} }
return false; return false;

View File

@ -29,12 +29,19 @@ final class MoveInterfacesToContractNamespaceDirectoryRectorTest extends Abstrac
__DIR__ . '/Expected/ExpectedRandomInterface.php', __DIR__ . '/Expected/ExpectedRandomInterface.php',
]; ];
// test skipped control factory // skip nette control factory
yield [ yield [
__DIR__ . '/Source/Control/ControlFactory.php', __DIR__ . '/Source/Control/ControlFactory.php',
$this->getFixtureTempDirectory() . '/Source/Control/ControlFactory.php', $this->getFixtureTempDirectory() . '/Source/Control/ControlFactory.php',
__DIR__ . '/Source/Control/ControlFactory.php', __DIR__ . '/Source/Control/ControlFactory.php',
]; ];
// skip form control factory
yield [
__DIR__ . '/Source/Control/FormFactory.php',
$this->getFixtureTempDirectory() . '/Source/Control/FormFactory.php',
__DIR__ . '/Source/Control/FormFactory.php',
];
} }
protected function getRectorClass(): string protected function getRectorClass(): string

View File

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Control; namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Control;
use Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Control\SomeControl;
interface ControlFactory interface ControlFactory
{ {
public function create(): SomeControl; public function create(): SomeControl;

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Control;
interface FormFactory
{
public function create(): SomeForm;
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Control;
use Nette\Application\UI\Form;
final class SomeForm extends Form
{
}

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Nette\Application\UI; namespace Nette\Application\UI;
if (class_exists('Nette\Forms\Form')) { if (class_exists('Nette\Application\UI')) {
return; return;
} }