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
Add function for getting the current numeric shell verbosity #48942
base: 6.3
Are you sure you want to change the base?
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Hey! Thanks for your PR. You are targeting branch "6.3" but it seems your PR description refers to branch "6.3 for features / 5.4, 6.0, 6.1, or 6.2 for bug fixes". Cheers! Carsonbot |
/** | ||
* Get shell verbosity. | ||
* | ||
* @param InputInterface $input |
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.
This @param
and @return
doc has no benefit. IMHO the whole phpdoc can be removed.
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.
Removed phpdoc
$shellVerbosity = 1; | ||
} | ||
if ($shellVerbosity) { | ||
$output->setVerbosity(1 << $shellVerbosity + 5); |
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.
This is a bit of magic here. i guess at least a comment would be helpful and maybe as wenn some tests to cover this.
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.
Added a comment. ApplicationTest::testRun asserts the verbosity of a command's output and will fail if this mapping is incorrect.
@maxbeckers I made some changes based on your comments |
Add
Application::getShellVerbosity
for getting the current numeric shell verbosity.This makes the code cleaner and allows us to do something like this to get the numeric verbosity level of an
InputInterface
:In my case I needed to get the verbosity of a dynamically built command call and found it too troublesome to get with the current tools.
Test pass and the functionality should remain the same as it is now.
The appropriate tests are here:
symfony/src/Symfony/Component/Console/Tests/ApplicationTest.php
Lines 1026 to 1056 in 21191d5
The PR is using the same internal verbosity levels from -1 to 3 as before. The following mapping is performed with a bit shift:
Perhaps a switch statement would be more readable but the bit shift makes for a neat one-liner.
OutputInterface::setVerbosity
is not called when verbosity is 0 because it wasn't called in the previous implementation either:symfony/src/Symfony/Component/Console/Application.php
Lines 919 to 961 in 21191d5