-
Notifications
You must be signed in to change notification settings - Fork 101
InvokableCommandInputAttributeRector test fixture #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
darthf1
wants to merge
1
commit into
rectorphp:main
Choose a base branch
from
darthf1:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...fony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/command_with_io.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Symfony\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\Fixture; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
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; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Symfony\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\Fixture; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
|
||
#[AsCommand('app:my-command')] | ||
final class MyCommand | ||
{ | ||
#[\Override] | ||
public function __invoke(\Symfony\Component\Console\Style\SymfonyStyle $io): int | ||
{ | ||
$io->info('Great success!'); | ||
|
||
return 1; | ||
} | ||
} | ||
?> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should not be replaced, skip the change should be the way, right? /cc @darthf1 @thePanz @gharlan could you verify? Thank you.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The blog post has this (almost) exact example, and there
$input
and$output
is changed into$io
as well.https://symfony.com/blog/new-in-symfony-7-3-invokable-commands-and-input-attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change in most of my commands after using the InvokableCommandInputAttributeRector.
But I also had some commands where I used the
$output
as argument for other functions. So there I still need the$output
param.Best would be:
$output
is not used anywhere in__invoke
=> remove$output
param altogether$output
is used fornew SymfonyStyle($input, $output)
=> do the change shown here in the pr$output
is used anywhere else => also keep the$output
param for__invoke
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this is a bugfix, I would keep a KISS solution: @samsonasik 's suggestion to not rewrite the parameters in the constructor looks reasonable as a first step.