Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 8 commits into from
Closed

Console table cleanup #19406

wants to merge 8 commits into from

Conversation

ReenExe
Copy link
Contributor

@ReenExe ReenExe commented Jul 22, 2016

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 -

if (!self::$styles[$name]) {
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
if (isset(self::$styles[$name])) {
return self::$styles[$name];
Copy link
Member

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?

Copy link
Contributor Author

@ReenExe ReenExe Jul 23, 2016

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'

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

@nicolas-grekas nicolas-grekas Jul 28, 2016

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

@nicolas-grekas
Copy link
Member

👍

@@ -115,7 +115,7 @@ public static function getStyleDefinition($name)
self::$styles = self::initStyles();
}

if (!self::$styles[$name]) {
if (empty(self::$styles[$name])) {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know :)

Copy link
Member

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().

Copy link
Contributor Author

@ReenExe ReenExe Jul 28, 2016

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for 2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@fabpot
Copy link
Member

fabpot commented Jul 28, 2016

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)?

@ReenExe
Copy link
Contributor Author

ReenExe commented Jul 28, 2016

@fabpot, try with cherry-pick but have conflicts. Can i make new PR in 2.7 (arm move changes) and close this PR?

@ReenExe
Copy link
Contributor Author

ReenExe commented Jul 28, 2016

Also in 2.7

  1. abcent method Table::setColumnStyle
  2. Use \InvalidArgumentException instead \Symfony\...\InvalidArgumentException

@nicolas-grekas
Copy link
Member

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).

@fabpot
Copy link
Member

fabpot commented Jul 28, 2016

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 fabpot closed this Jul 28, 2016
@fabpot fabpot reopened this Jul 28, 2016
@ReenExe
Copy link
Contributor Author

ReenExe commented Jul 28, 2016

@fabpot, i will try, but conflict stay between branches - it's normal?
In next time first changes make to 2.7 and next in master? (maybe miss some manual from Contributing)

@fabpot
Copy link
Member

fabpot commented Jul 28, 2016

Just submit a PR on 2.7 and I will take care of merge conflict myself.

@ReenExe
Copy link
Contributor Author

ReenExe commented Jul 28, 2016

Make new PR - thats only covers bugfix #19470

@ReenExe
Copy link
Contributor Author

ReenExe commented Jul 28, 2016

@fabpot, i see this after try submit (make my branch from master)
first-symfony-pr-conflict

fabpot pushed a commit that referenced this pull request Jul 28, 2016
fabpot added a commit that referenced this pull request Jul 28, 2016
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)
fabpot added a commit that referenced this pull request Jul 28, 2016
* 2.7:
  undefined offset fix (#19406)
  [EventDispatcher] Removed unused variable
@fabpot
Copy link
Member

fabpot commented Jul 28, 2016

Thank you @ReenExe.

fabpot added a commit that referenced this pull request Jul 28, 2016
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
@fabpot fabpot closed this Jul 28, 2016
fabpot added a commit that referenced this pull request Jul 30, 2016
* 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
fabpot added a commit that referenced this pull request Jul 30, 2016
* 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
fabpot added a commit that referenced this pull request Jul 30, 2016
* 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
This was referenced Jul 30, 2016
nicolas-grekas added a commit that referenced this pull request Aug 5, 2016
* 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
@fabpot fabpot mentioned this pull request Sep 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants