-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Console table cleanup #19406
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
Console table cleanup #19406
Conversation
if (!self::$styles[$name]) { | ||
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); | ||
if (isset(self::$styles[$name])) { | ||
return self::$styles[$name]; |
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.
What is the advantage of this change?
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.
$array = [
'default' => new TableStyle(),
];
if (!$array['name']) {
}
// undefined offset 'name'
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'd keep the original order: throw, then return, which means changing this line to
if (empty(self::$styles[$name])) {
(using empty()
to keep throwing when defined but value is == false
)
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.
@nicolas-grekas, Done
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.
@ReenExe did you forget to push?
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.
@nicolas-grekas, now good? Or need change?
Sorry, hard understand what need change after last comment
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.
yes, needs change to me
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.
@nicolas-grekas, need add reviewed
label?
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.
but I don't see any change on the discussed line/code block, did you forget to push?
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.
Yes, is my mistake
i extract method to resolveStyle
if ($name instanceof TableStyle) {
return $name;
}
if (isset(self::$styles[$name])) {
return self::$styles[$name];
}
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
And in getStyleDefinition
change
if (!self::$styles[$name]) {
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
}
return self::$styles[$name];
to
if (isset(self::$styles[$name])) {
return self::$styles[$name];
}
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
But after review need changes to:
if (empty(self::$styles[$name])) {
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
}
return self::$styles[$name];
So a think must be same code - and make same changes in both places
@@ -694,6 +694,25 @@ public function testColumnWiths() | |||
$this->assertEquals($expected, $this->getOutputContent($output)); | |||
} | |||
|
|||
/** | |||
* @expectedException \InvalidArgumentException |
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.
\Symfony\Component\Console\Exception\InvalidArgumentException
👍 |
@@ -115,7 +115,7 @@ public static function getStyleDefinition($name) | |||
self::$styles = self::initStyles(); | |||
} | |||
|
|||
if (!self::$styles[$name]) { | |||
if (empty(self::$styles[$name])) { |
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.
Why not using isset()
here?
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.
By my suggestion: using isset would be written as:
if (isset(self::$styles[$name]) && !self::$styles[$name]) {
which happens to be exactly what empty()
does.
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.
When can the style be falsy?
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 don't know :)
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.
Reading the code, it looks like it is defined with an object or not defined at all. So, I think we should keep isset()
as before in the new resolveStyle()
method and change this one to use isset()
as well. Whenever possible, I tend to avoid using empty()
.
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.
@fabpot, before little change - what prefer?
1
if ($name instanceof TableStyle) {
return $name;
}
if (!isset(self::$styles[$name])) {
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
}
return self::$styles[$name];
or
2:
if ($name instanceof TableStyle) {
return $name;
}
if (isset(self::$styles[$name])) {
return self::$styles[$name];
}
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
As for me is 2
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.
Ok for 2
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.
Done
LGTM now. Can you submit another PR for Symfony 2.7 (keep this one open as it's going to be merged as well for more recent versions of Symfony)? |
@fabpot, try with cherry-pick but have conflicts. Can i make new PR in 2.7 (arm move changes) and close this PR? |
Also in 2.7
|
you should close this one yes, then open a new one against 2.7, then if you'd like another one against the first branch where setColumnStyle exists (and so on). |
No, please, don't close this one. @ReenExe You are right, that's why I need a specific PR for 2.7. This one will still be merged for the additional changes. Thanks. |
@fabpot, i will try, but conflict stay between branches - it's normal? |
Just submit a PR on 2.7 and I will take care of merge conflict myself. |
Make new PR - thats only covers bugfix #19470 |
@fabpot, i see this after try submit (make my branch from |
This PR was squashed before being merged into the 2.7 branch (closes #19470). Discussion ---------- undefined offset fix (#19406) | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 9813888 undefined offset fix (#19406)
* 2.7: undefined offset fix (#19406) [EventDispatcher] Removed unused variable
Thank you @ReenExe. |
This PR was submitted for the master branch but it was merged into the 2.8 branch instead (closes #19406). Discussion ---------- Console table cleanup | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes `notice` | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 217274b Console table cleanup
* 2.8: Minor fixes [Console] Overcomplete argument exception message tweak. fixed bad auto merge Console table cleanup undefined offset fix (#19406) [EventDispatcher] Removed unused variable
* 3.0: Minor fixes [Console] Overcomplete argument exception message tweak. fixed bad auto merge Console table cleanup undefined offset fix (#19406) [EventDispatcher] Removed unused variable
* 3.1: Minor fixes [Cache] Fix abstract AdapterTestCase cache property [Console] Overcomplete argument exception message tweak. fixed bad auto merge Console table cleanup undefined offset fix (#19406) [EventDispatcher] Removed unused variable
* 2.8: Relax 1 test failing with latest PHP versions bumped Symfony version to 2.8.10 Remove usage of __CLASS__ outside of a class [HttpKernel] Fix variable conflicting name [Process] Fix double-fread() when reading unix pipes [Process] Fix AbstractPipes::write() for a situation seen on HHVM (at least) [Validator] Fix dockblock typehint in XmlFileLoader bumped Symfony version to 2.8.10 updated VERSION for 2.8.9 updated CHANGELOG for 2.8.9 bumped Symfony version to 2.7.17 updated VERSION for 2.7.16 update CONTRIBUTORS for 2.7.16 updated CHANGELOG for 2.7.16 Minor fixes [Console] Overcomplete argument exception message tweak. fixed bad auto merge Console table cleanup undefined offset fix (#19406) [EventDispatcher] Removed unused variable Conflicts: CHANGELOG-2.7.md CHANGELOG-3.0.md src/Symfony/Bridge/Swiftmailer/DataCollector/MessageDataCollector.php src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php src/Symfony/Component/Console/Tests/Helper/LegacyDialogHelperTest.php src/Symfony/Component/Console/Tests/Helper/TableTest.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container9.php src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/LegacyPdoSessionHandlerTest.php src/Symfony/Component/HttpKernel/Kernel.php
notice