diff --git a/config/set/symfony52.php b/config/set/symfony52.php index 7a22f95b2180..7f3a7816226a 100644 --- a/config/set/symfony52.php +++ b/config/set/symfony52.php @@ -6,6 +6,7 @@ use Rector\Renaming\Rector\MethodCall\RenameMethodRector; use Rector\Renaming\ValueObject\MethodCallRename; use Rector\Renaming\ValueObject\RenameClassConstant; +use Rector\Symfony\Rector\StaticCall\BinaryFileResponseCreateToNewInstanceRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\SymfonyPhpConfig\ValueObjectInliner; @@ -16,6 +17,9 @@ $services = $containerConfigurator->services(); + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#httpfoundation + $services->set(BinaryFileResponseCreateToNewInstanceRector::class); + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#mime $services->set(RenameMethodRector::class) ->call('configure', [[ diff --git a/rules/symfony/src/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector.php b/rules/symfony/src/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector.php new file mode 100644 index 000000000000..ca5f5b651544 --- /dev/null +++ b/rules/symfony/src/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector.php @@ -0,0 +1,84 @@ +class instanceof Name) { + return null; + } + + if (! $this->isName($node->class, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { + return null; + } + + if (! $this->isName($node->name, 'create')) { + return null; + } + + $args = $node->args; + if ([] === $args) { + $args[] = $this->createArg($this->createNull()); + } + + return new New_($node->class, $args); + } +} diff --git a/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/BinaryFileResponseCreateToNewInstanceRectorTest.php b/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/BinaryFileResponseCreateToNewInstanceRectorTest.php new file mode 100644 index 000000000000..7c3aaf8eb298 --- /dev/null +++ b/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/BinaryFileResponseCreateToNewInstanceRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return BinaryFileResponseCreateToNewInstanceRector::class; + } +} diff --git a/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/Fixture/create_with_argument.php.inc b/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/Fixture/create_with_argument.php.inc new file mode 100644 index 000000000000..2918d1402498 --- /dev/null +++ b/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/Fixture/create_with_argument.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/Fixture/create_without_arguments.php.inc b/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/Fixture/create_without_arguments.php.inc new file mode 100644 index 000000000000..76f386fddd66 --- /dev/null +++ b/rules/symfony/tests/Rector/StaticCall/BinaryFileResponseCreateToNewInstanceRector/Fixture/create_without_arguments.php.inc @@ -0,0 +1,31 @@ + +----- +