Skip to content

Incorrect behavior of InvokableCommandInputAttributeRector #9254

@darthf1

Description

@darthf1

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/7268bb7d-7a4f-4485-b43e-c5cb83a4c65b

<?php

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand('app:my-command')]
final class MyCommand extends Command
{
    #[\Override]
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
	$io->info('Great success!');

	return 1;
    }
}

Responsible rules

  • InvokableCommandInputAttributeRector

Expected Behavior

 use Symfony\Component\Console\Style\SymfonyStyle;
 
 #[AsCommand('app:my-command')]
-final class MyCommand extends Command
+final class MyCommand
 {
     #[\Override]
-    protected function execute(InputInterface $input, OutputInterface $output): int
-    {
-        $io = new SymfonyStyle($input, $output);
-	 $io->info('Great success!');
-
-	return 1;
+    public function __invoke(\Symfony\Component\Console\Style\SymfonyStyle $io): int
+    {
+        $io->info('Great success!');
+        return 1;
     }
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions