mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
Merge pull request #3551 from rectorphp/inter-form
skip Form factories too
This commit is contained in:
commit
cf663c4fe7
@ -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;
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Control;
|
||||||
|
|
||||||
|
interface FormFactory
|
||||||
|
{
|
||||||
|
public function create(): SomeForm;
|
||||||
|
}
|
@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user