Fix `fix` command to handle `--fixers` option when contains extra and excluding fixers #599

Merged
merged 4 commits into from Nov 2, 2014

Conversation

Projects
None yet
6 participants
@fivestar
Contributor

fivestar commented Sep 25, 2014

Currently, when --fixers option contains extra and excluding mixed filters such as -eol_ending,concat_with_spaces, excluding filter will be enabled, however, extra filter will not be enabled.

This PR fixes this behavior, so enable both type filters when mixed filters given.


sample.php

<?php
echo 'foo'.'bar', PHP_EOL;

Current version: (concat_with_spaces is not enabled)

% php-cs-fixer fix -v --diff --fixers="-eol_ending,concat_with_spaces" --dry-run sample.php   
   1) /home/fivestar/sample.php (eof_ending)
      ---------- begin diff ----------
      --- Original
      +++ New
      @@ @@
       <?php
       echo 'foo'.'bar', PHP_EOL;

      -

      ---------- end diff ----------

Fixed version: (concat_with_spaces is enabled)

% php-cs-fixer fix -v --diff --fixers="-eol_ending,concat_with_spaces" --dry-run sample.php 
   1) /home/fivestar/sample.php (eof_ending, concat_with_spaces)
      ---------- begin diff ----------
      --- Original
      +++ New
      @@ @@
       <?php
      -echo 'foo'.'bar', PHP_EOL;
      -
      +echo 'foo' . 'bar', PHP_EOL;


      ---------- end diff ----------
Symfony/CS/Console/FixersResolver.php
+ $this->config = $config;
+ }
+
+ public function resolve($levelOption, $fixersOption)

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

Really, create extra class and do everything in one, the only one method?

@keradus

keradus Sep 25, 2014

Member

Really, create extra class and do everything in one, the only one method?

This comment has been minimized.

@fivestar

fivestar Sep 25, 2014

Contributor

Why create extra class is because to get testability and separate responsibilities.

@fivestar

fivestar Sep 25, 2014

Contributor

Why create extra class is because to get testability and separate responsibilities.

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

Cool! but why only one magic method to do all things?

@keradus

keradus Sep 25, 2014

Member

Cool! but why only one magic method to do all things?

Symfony/CS/Console/FixersResolver.php
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\CS\Console;

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

You use it in console, but it does not do anything with console. It should not be in Console namespace

@keradus

keradus Sep 25, 2014

Member

You use it in console, but it does not do anything with console. It should not be in Console namespace

This comment has been minimized.

@fivestar

fivestar Sep 25, 2014

Contributor

Certainly this class is not dependent on Console, but this class handles CLI options (especially $filterOption).
Considering the task for this class, so I think this class have to be under the Console namespace.

Where is better? Util\ or else? Tell me what you think!

@fivestar

fivestar Sep 25, 2014

Contributor

Certainly this class is not dependent on Console, but this class handles CLI options (especially $filterOption).
Considering the task for this class, so I think this class have to be under the Console namespace.

Where is better? Util\ or else? Tell me what you think!

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

I would agree if it manipulate only on console inputs. But it handle also Config and Fixer (or only Config, if you changed it) classes.
I would put it into Symfony\CS directry. But that's only my opinion.

@keradus

keradus Sep 25, 2014

Member

I would agree if it manipulate only on console inputs. But it handle also Config and Fixer (or only Config, if you changed it) classes.
I would put it into Symfony\CS directry. But that's only my opinion.

Symfony/CS/Console/FixersResolver.php
+
+ public function resolve($levelOption, $fixersOption)
+ {
+ $allFixers = $this->fixer->getFixers();

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

IMO this should be passed into class - the defined Fixers, not Fixer itself.

@keradus

keradus Sep 25, 2014

Member

IMO this should be passed into class - the defined Fixers, not Fixer itself.

This comment has been minimized.

@fivestar

fivestar Sep 25, 2014

Contributor

Okay.

@fivestar

fivestar Sep 25, 2014

Contributor

Okay.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Sep 25, 2014

Member

Maybe this is good plase to separate Config::$fixers into two values?
One that handle LEVEL, and second that handle fixers array? Now this props handle both :(

Member

keradus commented Sep 25, 2014

Maybe this is good plase to separate Config::$fixers into two values?
One that handle LEVEL, and second that handle fixers array? Now this props handle both :(

Symfony/CS/Console/FixersResolver.php
+ $addNames = [];
+ $removeNames = [];
+ foreach ($names as $name) {
+ if (strpos($name, '-') === 0) {

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

please use Symfony standards here: 0 === $sth

@keradus

keradus Sep 25, 2014

Member

please use Symfony standards here: 0 === $sth

This comment has been minimized.

@fivestar

fivestar Sep 25, 2014

Contributor

I see.

@fivestar

fivestar Sep 25, 2014

Contributor

I see.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Sep 25, 2014

Member

Idea itself looks nice!
It would be great to add info about levels/fixers and mixing them (with excluding/including extra fixers) into readme.
I know that this is not intuitive now.

Member

keradus commented Sep 25, 2014

Idea itself looks nice!
It would be great to add info about levels/fixers and mixing them (with excluding/including extra fixers) into readme.
I know that this is not intuitive now.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Sep 25, 2014

Member

Fix fix command to handle --filter option

--filter? where?

Member

keradus commented Sep 25, 2014

Fix fix command to handle --filter option

--filter? where?

Symfony/CS/Console/FixersResolver.php
+
+ // remove/add fixers based on the fixers option
+ $names = array_map('trim', explode(',', $fixersOption));
+ $addNames = [];

This comment has been minimized.

@keradus

keradus Sep 25, 2014

Member

crash on php5.2

@keradus

keradus Sep 25, 2014

Member

crash on php5.2

This comment has been minimized.

@stof

stof Oct 4, 2014

Contributor

on PHP 5.3, not on 5.2 (the whole library crashes on 5.2 because it uses namespaces)

@stof

stof Oct 4, 2014

Contributor

on PHP 5.3, not on 5.2 (the whole library crashes on 5.2 because it uses namespaces)

This comment has been minimized.

@keradus

keradus Oct 4, 2014

Member

yes, @fivestar point it out 9 days ago and I already sorry for my typo ;)

@keradus

keradus Oct 4, 2014

Member

yes, @fivestar point it out 9 days ago and I already sorry for my typo ;)

@fivestar fivestar changed the title from Fix `fix` command to handle `--filter` option when contains extra and excluding filters to Fix `fix` command to handle `--fixers` option when contains extra and excluding filters Sep 25, 2014

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Sep 25, 2014

Contributor

Thanks for your comments! I replied some line notes.

  • Sorry --filter is mistaken. --fixers is right. Do i have to amend commit message?
  • Will be fix php5.2 (5.3?) crash.
  • Maybe this is good plase to separate Config::$fixers into two values?
    One that handle LEVEL, and second that handle fixers array? Now this props handle both :(

    • Do you have any ideas? Maybe current code has any problems?
  • It would be great to add info about levels/fixers and mixing them (with excluding/including extra fixers) into readme.

    • I'll see what I can do.
Contributor

fivestar commented Sep 25, 2014

Thanks for your comments! I replied some line notes.

  • Sorry --filter is mistaken. --fixers is right. Do i have to amend commit message?
  • Will be fix php5.2 (5.3?) crash.
  • Maybe this is good plase to separate Config::$fixers into two values?
    One that handle LEVEL, and second that handle fixers array? Now this props handle both :(

    • Do you have any ideas? Maybe current code has any problems?
  • It would be great to add info about levels/fixers and mixing them (with excluding/including extra fixers) into readme.

    • I'll see what I can do.
@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Sep 25, 2014

Member

Do i have to amend commit message?

If you will keep this PR with only one commit then please, do it. If PR will has several then I will do it during merge.

Will be fix php5.2 (5.3?) crash.

Yeah, 5.3, sorry ;)

Maybe this is good plase to separate Config::$fixers into two values?

Do you have any ideas? Maybe current code has any problems?

No problems on that, just now we have one variable with dual responsibility. You are dealing with them now so it will be cool to fix it as well ;) Just create Config::$level for level value and change Config::$fixers to handle only fixers array

Member

keradus commented Sep 25, 2014

Do i have to amend commit message?

If you will keep this PR with only one commit then please, do it. If PR will has several then I will do it during merge.

Will be fix php5.2 (5.3?) crash.

Yeah, 5.3, sorry ;)

Maybe this is good plase to separate Config::$fixers into two values?

Do you have any ideas? Maybe current code has any problems?

No problems on that, just now we have one variable with dual responsibility. You are dealing with them now so it will be cool to fix it as well ;) Just create Config::$level for level value and change Config::$fixers to handle only fixers array

@keradus keradus changed the title from Fix `fix` command to handle `--fixers` option when contains extra and excluding filters to Fix `fix` command to handle `--fixers` option when contains extra and excluding fixers Sep 25, 2014

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Sep 26, 2014

Member

Please rebase on master ;)

Member

keradus commented Sep 26, 2014

Please rebase on master ;)

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Sep 30, 2014

Member

any news @fivestar ? The work you have already done is cool!

Member

keradus commented Sep 30, 2014

any news @fivestar ? The work you have already done is cool!

@keradus keradus added the bug label Sep 30, 2014

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 1, 2014

Contributor

Sorry, I've been so busy lately... Please wait for a little while longer!

Contributor

fivestar commented Oct 1, 2014

Sorry, I've been so busy lately... Please wait for a little while longer!

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 6, 2014

Contributor

@keradus Please check it!

Contributor

fivestar commented Oct 6, 2014

@keradus Please check it!

- }
- }
+ $fixers = $fixersResolver->resolveByLevel($levelOption);
+ $fixers = $fixersResolver->resolveByNames($fixers, $fixersOption);

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

So we have here sth like:

$fixersResolver = new FixersResolver($this->fixer->getFixers());
$fixers = $fixersResolver->resolveByLevel($levelOption);
$fixers = $fixersResolver->resolveByNames($fixers, $fixersOption);

So we passing $fixersOption, $levelOption, $fixers and $fixersOption, where$levelOptionis calculated here from$config->getFixers();or input itself. We also calculate sth fromFixersResolverand passing it toFixerResolver` again - just use a state.

It would be great if you have some setters to set $level and $fixers from input/config, then resolveBy* would be a private methods and at finish FixersResolver will have some public method like getFixers/resolve (which do all the magic like parsing inputs and calling private helpers)

@keradus

keradus Oct 6, 2014

Member

So we have here sth like:

$fixersResolver = new FixersResolver($this->fixer->getFixers());
$fixers = $fixersResolver->resolveByLevel($levelOption);
$fixers = $fixersResolver->resolveByNames($fixers, $fixersOption);

So we passing $fixersOption, $levelOption, $fixers and $fixersOption, where$levelOptionis calculated here from$config->getFixers();or input itself. We also calculate sth fromFixersResolverand passing it toFixerResolver` again - just use a state.

It would be great if you have some setters to set $level and $fixers from input/config, then resolveBy* would be a private methods and at finish FixersResolver will have some public method like getFixers/resolve (which do all the magic like parsing inputs and calling private helpers)

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

+ if (null === $levelOption
+ && (empty($fixersOption) || preg_match('{(^|,)-}', $fixersOption))
+ ) {
+ $levelOption = $config->getFixers();

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

I would break a BC here - let the Config::getFixers returns fixers array and Config::getLevel returns level constant.
It will not be confusing then.

@keradus

keradus Oct 6, 2014

Member

I would break a BC here - let the Config::getFixers returns fixers array and Config::getLevel returns level constant.
It will not be confusing then.

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/FixersResolver.php
+
+ if (is_string($levelOption)) {
+ switch ($levelOption) {
+ case 'psr0':

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

just do the mapping:
static array $foo = array('psr0' => FixerInterface::PSR0_LEVEL, ...);

@keradus

keradus Oct 6, 2014

Member

just do the mapping:
static array $foo = array('psr0' => FixerInterface::PSR0_LEVEL, ...);

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/FixersResolver.php
+ }
+
+ // select base fixers for the given level
+ if (is_array($level)) {

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

$level should not be an array of fixers, array of fixers should be in $fixers.
This will lead to breaking BC as mentioned before.

@keradus

keradus Oct 6, 2014

Member

$level should not be an array of fixers, array of fixers should be in $fixers.
This will lead to breaking BC as mentioned before.

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/FixersResolver.php
+ $removeNames = array();
+ foreach ($names as $name) {
+ if (0 === strpos($name, '-')) {
+ $removeNames[] = ltrim($name, '-');

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

I would use ~map here instead of array (in $addNames the same):
$removeNames[$name] = true

then you will not need to chek in_array($name $removeNames, true) but just isset($removeNames[$name])

@keradus

keradus Oct 6, 2014

Member

I would use ~map here instead of array (in $addNames the same):
$removeNames[$name] = true

then you will not need to chek in_array($name $removeNames, true) but just isset($removeNames[$name])

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

btw, with larges arrays it would be a little faster i think

@keradus

keradus Oct 6, 2014

Member

btw, with larges arrays it would be a little faster i think

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/FixersResolver.php
+ return $fixers;
+ }
+
+ public function resolveByNames(array $fixers, $names)

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

I think array $fixers is a state of this class, it should not be passed in and out.
calculate it inside class and make a getter for it.

@keradus

keradus Oct 6, 2014

Member

I think array $fixers is a state of this class, it should not be passed in and out.
calculate it inside class and make a getter for it.

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/Tests/FixersResolverTest.php
+
+ foreach ($fixers as $fixer) {
+ switch ($fixer->getName()) {
+ case 'encoding': // psr1

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

And what if sb change this name of Fixer?
Please get it from fixer class itself.

@keradus

keradus Oct 6, 2014

Member

And what if sb change this name of Fixer?
Please get it from fixer class itself.

This comment has been minimized.

@keradus

keradus Oct 6, 2014

Member

oh, you have it in line 44 already.
ok, no big deal

@keradus

keradus Oct 6, 2014

Member

oh, you have it in line 44 already.
ok, no big deal

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 6, 2014

Member

Nice progress @fivestar ;)
But I think it needs just a little more (see code comments)

Member

keradus commented Oct 6, 2014

Nice progress @fivestar ;)
But I think it needs just a little more (see code comments)

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 9, 2014

Member

It would be great to see that on master! Waiting for progress ;)

Member

keradus commented Oct 9, 2014

It would be great to see that on master! Waiting for progress ;)

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 13, 2014

Member

@fivestar please rebase on master ;)
Any news on that btw? I would really appreciate to see that finished ;)

Member

keradus commented Oct 13, 2014

@fivestar please rebase on master ;)
Any news on that btw? I would really appreciate to see that finished ;)

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 16, 2014

Contributor

Thank you for waiting! I fixed FixersResolver and Config interface. Please check again.

Contributor

fivestar commented Oct 16, 2014

Thank you for waiting! I fixed FixersResolver and Config interface. Please check again.

Symfony/CS/FixersResolver.php
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Katsuhiro Ogawa <ko.fivestar@gmail.com>
+ */
+class FixersResolver

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member

whole class needs a documentation

@keradus

keradus Oct 16, 2014

Member

whole class needs a documentation

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/FixersResolver.php
+ $names = array_map('trim', explode(',', $fixerOption));
+ }
+
+ return $names;

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member
if (null === $fixerOptions) {
    return $this->config->getFixers();
}

return array_map('trim', explode(',', $fixerOption));
@keradus

keradus Oct 16, 2014

Member
if (null === $fixerOptions) {
    return $this->config->getFixers();
}

return array_map('trim', explode(',', $fixerOption));

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/Tests/FixersResolverTest.php
+{
+ protected function setUp()
+ {
+ $this->fixer = new Fixer();

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member

Please use only declared properties.
You should declare $fixer, $config and $resolver.

@keradus

keradus Oct 16, 2014

Member

Please use only declared properties.
You should declare $fixer, $config and $resolver.

This comment has been minimized.

Symfony/CS/FixersResolver.php
+ );
+
+ if (isset($levelMap[$levelOption])) {
+ $level = $levelMap[$levelOption];

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member
if (isset...) {
    return...
}

if (null === ...) {
    return ...
}

throw new ...;
@keradus

keradus Oct 16, 2014

Member
if (isset...) {
    return...
}

if (null === ...) {
    return ...
}

throw new ...;

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done.

@keradus

keradus Oct 27, 2014

Member

already done.

Symfony/CS/FixersResolver.php
+ public function __construct(array $allFixers, ConfigInterface $config)
+ {
+ $this->allFixers = $allFixers;
+ $this->fixers = $allFixers;

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member

IMO you should NOT set $this->fixers = $allFixers; at start.

@keradus

keradus Oct 16, 2014

Member

IMO you should NOT set $this->fixers = $allFixers; at start.

This comment has been minimized.

This comment has been minimized.

@fivestar

fivestar Oct 27, 2014

Contributor

oh I forgot

@fivestar

fivestar Oct 27, 2014

Contributor

oh I forgot

Symfony/CS/FixersResolver.php
+
+ protected function resolveByLevel($levelOption, $fixerOption)
+ {
+ $level = $this->parseLevelOption($levelOption, $fixerOption);

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member

What if parseLevelOption returns null?

@keradus

keradus Oct 16, 2014

Member

What if parseLevelOption returns null?

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

already done

@keradus

keradus Oct 27, 2014

Member

already done

README.rst
@@ -337,7 +343,7 @@ and directories that need to be analyzed:
;
You may also use a blacklist for the Fixers instead of the above shown whitelist approach.
-The following example shows how to use all Fixers but the `psr0` fixer.
+The following example shows how to use all PSR-2 Fixers but the `psr0` fixer.

This comment has been minimized.

@keradus

keradus Oct 16, 2014

Member

No comments here, so if I am wrong please correct me.
We have configLevel, configFixers, optionLevel, optionFixers.

If optionFixers is set we take it, if not we take configFixers. Great.

If optionLevel is set we take it. Great.
If optionLevel is not set and fixerOption is not set then we take configLevel. Great.
If optionLevel is not set and fixerOption is set - why we take configLevel if any of fixerOption is exclusion?

If I use --fixers=aaa,-bbb,ccc what fixers will be used?
All with default level (SYMFONY) without bbb but with aaa & ccc?

If I use --fixers=aaa,ccc what fixers will be used?
Only aaa,ccc (Without using all fixers at SYMFONY level)?

If I am reading it correctly then this will be cool ;) But it will be also worth to write it down in readme as well.

@keradus

keradus Oct 16, 2014

Member

No comments here, so if I am wrong please correct me.
We have configLevel, configFixers, optionLevel, optionFixers.

If optionFixers is set we take it, if not we take configFixers. Great.

If optionLevel is set we take it. Great.
If optionLevel is not set and fixerOption is not set then we take configLevel. Great.
If optionLevel is not set and fixerOption is set - why we take configLevel if any of fixerOption is exclusion?

If I use --fixers=aaa,-bbb,ccc what fixers will be used?
All with default level (SYMFONY) without bbb but with aaa & ccc?

If I use --fixers=aaa,ccc what fixers will be used?
Only aaa,ccc (Without using all fixers at SYMFONY level)?

If I am reading it correctly then this will be cool ;) But it will be also worth to write it down in readme as well.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 16, 2014

Member

Again you made cool work here! I'm glad to see that!
I hope we make this merged before release of 1.0

Member

keradus commented Oct 16, 2014

Again you made cool work here! I'm glad to see that!
I hope we make this merged before release of 1.0

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 27, 2014

Contributor

I'm sorry for my late response, and thank you for your help!I was updated the README. Please check it.
But, I'm not good at English, if my description is not well, so please want to fix it.

Contributor

fivestar commented Oct 27, 2014

I'm sorry for my late response, and thank you for your help!I was updated the README. Please check it.
But, I'm not good at English, if my description is not well, so please want to fix it.

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 27, 2014

Contributor

Thank you for your comments. README was fixed. Am I correct?

Contributor

fivestar commented Oct 27, 2014

Thank you for your comments. README was fixed. Am I correct?

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 27, 2014

Member

IMO yes, README was fixed (one minor in commit's comment), but I am not perfect at english either

Member

keradus commented Oct 27, 2014

IMO yes, README was fixed (one minor in commit's comment), but I am not perfect at english either

Symfony/CS/Tests/FixersResolverTest.php
+
+ $config = new Config();
+
+ $this->resolver = new FixersResolver($fixer->getFixers(), $config);

This comment has been minimized.

@keradus

keradus Oct 27, 2014

Member

You should declare $resolver property in FixersResolverTest class.

@keradus

keradus Oct 27, 2014

Member

You should declare $resolver property in FixersResolverTest class.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 27, 2014

Member

Could you rebase your branch to remove merge commit and squash commits of same author, please?

Of course after that two minors ;)

Member

keradus commented Oct 27, 2014

Could you rebase your branch to remove merge commit and squash commits of same author, please?

Of course after that two minors ;)

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 27, 2014

Contributor

Well, I fixed the README and rebased this branch!

Contributor

fivestar commented Oct 27, 2014

Well, I fixed the README and rebased this branch!

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 27, 2014

Contributor

I have one last commit that add test cases for FixersResolver.

Contributor

fivestar commented Oct 27, 2014

I have one last commit that add test cases for FixersResolver.

Symfony/CS/Tests/FixersResolverTest.php
+
+ public function testGetFixersReturnsEmptyArrayByDefault()
+ {
+ $this->assertEquals([], $this->resolver->getFixers());

This comment has been minimized.

@keradus

keradus Oct 28, 2014

Member

This will fail on PHP 5.3...
Also please squash commits after 6876726

@keradus

keradus Oct 28, 2014

Member

This will fail on PHP 5.3...
Also please squash commits after 6876726

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 28, 2014

Contributor

OMG. I really fixed.

Contributor

fivestar commented Oct 28, 2014

OMG. I really fixed.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 28, 2014

Member

Just need to squash commits after 6876726 ;)

👍

Member

keradus commented Oct 28, 2014

Just need to squash commits after 6876726 ;)

👍

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 28, 2014

Member

I test this branch a lot, results are below.


             CONFIG      OPTION
LEVEL           X
FIXERS

Result: Take level from config.
OK


             CONFIG      OPTION
LEVEL           X
FIXERS          X

Result:
If fixers from config have only "positive" fixers: Take fixers from config and ignore level from config.
If fixers from config have "negative" fixers: Take level from config and apply fixers from config as patch.
ERROR: In both cases the fixers from config should be applied as patch.


             CONFIG      OPTION
LEVEL           X           X
FIXERS

Result: Take level from option.
OK


             CONFIG      OPTION
LEVEL           X           X
FIXERS          X           X

Result: Take level from option and apply fixers from options as patch.
OK


             CONFIG      OPTION
LEVEL           X
FIXERS          X           X

Result:
If fixers from options have only "positive" fixers: Take fixers from option and ignore level from config.
If fixers from options have "negative" fixers: Take level from config and apply fixers from option as patch.
OK


             CONFIG      OPTION
LEVEL           X           X
FIXERS          X

Result: Take level from option and ignore level from config. Then apply fixers from config as patch.
ERROR: Fixer from config should not be applied.


When sb run php-cs-fixer fix --level=symfony then one want to run only the level he set, without fixers from config as patch

Member

keradus commented Oct 28, 2014

I test this branch a lot, results are below.


             CONFIG      OPTION
LEVEL           X
FIXERS

Result: Take level from config.
OK


             CONFIG      OPTION
LEVEL           X
FIXERS          X

Result:
If fixers from config have only "positive" fixers: Take fixers from config and ignore level from config.
If fixers from config have "negative" fixers: Take level from config and apply fixers from config as patch.
ERROR: In both cases the fixers from config should be applied as patch.


             CONFIG      OPTION
LEVEL           X           X
FIXERS

Result: Take level from option.
OK


             CONFIG      OPTION
LEVEL           X           X
FIXERS          X           X

Result: Take level from option and apply fixers from options as patch.
OK


             CONFIG      OPTION
LEVEL           X
FIXERS          X           X

Result:
If fixers from options have only "positive" fixers: Take fixers from option and ignore level from config.
If fixers from options have "negative" fixers: Take level from config and apply fixers from option as patch.
OK


             CONFIG      OPTION
LEVEL           X           X
FIXERS          X

Result: Take level from option and ignore level from config. Then apply fixers from config as patch.
ERROR: Fixer from config should not be applied.


When sb run php-cs-fixer fix --level=symfony then one want to run only the level he set, without fixers from config as patch

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 28, 2014

Member

@fabpot @fivestar @stof @sstok @GrahamCampbell
what do you think about above strategy of dealing with level/fixers config/options ?

BTW, tests and solution for that behavior are availeble here: fivestar#2

Member

keradus commented Oct 28, 2014

@fabpot @fivestar @stof @sstok @GrahamCampbell
what do you think about above strategy of dealing with level/fixers config/options ?

BTW, tests and solution for that behavior are availeble here: fivestar#2

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 28, 2014

Contributor

Thanks!! I misread your specified commit number so I'll squash after merging your PR ;)

Contributor

fivestar commented Oct 28, 2014

Thanks!! I misread your specified commit number so I'll squash after merging your PR ;)

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 29, 2014

Contributor

I've seen test results and your PR, so I think your strategy is better because it's is useful for actual use case.
If you judge your PR can merge, please call me again.

Contributor

fivestar commented Oct 29, 2014

I've seen test results and your PR, so I think your strategy is better because it's is useful for actual use case.
If you judge your PR can merge, please call me again.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 29, 2014

Member

I am not PR-ing with code I don't want to be merged ;)
(Sth I use WIP flag to show that PR is not done yet).

If you agreed with changes just accept that PR (fivestar#2). I don't change the whole strategy - just fix 2 cases.

The other thing is if this PR (#599) will be merged - and I will be glad to see more opinions here.
For me it should be ;)

Member

keradus commented Oct 29, 2014

I am not PR-ing with code I don't want to be merged ;)
(Sth I use WIP flag to show that PR is not done yet).

If you agreed with changes just accept that PR (fivestar#2). I don't change the whole strategy - just fix 2 cases.

The other thing is if this PR (#599) will be merged - and I will be glad to see more opinions here.
For me it should be ;)

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 29, 2014

Contributor

Ok I merged your PR. (What is WIP? I can't find the keyword)
What should I do sth else?

Contributor

fivestar commented Oct 29, 2014

Ok I merged your PR. (What is WIP? I can't find the keyword)
What should I do sth else?

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 29, 2014

Member
  • WIP stands for Work In Progress
  • 6f0cb71 and 97a8abf should be squashed
  • I want to wait a little for some other opinions about this PR. I will be glad to see them.
Member

keradus commented Oct 29, 2014

  • WIP stands for Work In Progress
  • 6f0cb71 and 97a8abf should be squashed
  • I want to wait a little for some other opinions about this PR. I will be glad to see them.
@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 29, 2014

Contributor

Uh oh I thought you are judged. I'll remove commits later. Please resend PR.

Contributor

fivestar commented Oct 29, 2014

Uh oh I thought you are judged. I'll remove commits later. Please resend PR.

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Oct 29, 2014

Member

I'll remove commits later. Please resend PR.

Why to remove? The new commits are good - they improve this PR (#599).
Just please squash them.

Uh oh I thought you are judged.

Yes, I can perform a merge. But since this PR change tool interface and break BC it is worthly to give community a time to give a feedback with opinion :)

Member

keradus commented Oct 29, 2014

I'll remove commits later. Please resend PR.

Why to remove? The new commits are good - they improve this PR (#599).
Just please squash them.

Uh oh I thought you are judged.

Yes, I can perform a merge. But since this PR change tool interface and break BC it is worthly to give community a time to give a feedback with opinion :)

@radziem

This comment has been minimized.

Show comment
Hide comment

radziem commented Oct 29, 2014

👍

+
+In combination with these config and command line options, you can choose various usage.
+
+For example, default level is ``symfony``, but if you also don't want to use ``psr0`` fixer, you can specify ``--fixers="-psr0"`` option.

This comment has been minimized.

@sstok

sstok Oct 29, 2014

Contributor

but if you also don't want to use the psr0 fixer.

you can specify the --fixers="-psr0" option.

And try to wrap lines a bit ;) approx 80 chars max

@sstok

sstok Oct 29, 2014

Contributor

but if you also don't want to use the psr0 fixer.

you can specify the --fixers="-psr0" option.

And try to wrap lines a bit ;) approx 80 chars max

@@ -197,6 +202,23 @@ protected function configure()
?>
+The ``symfony`` level is set by default, you can also change default level:

This comment has been minimized.

@sstok

sstok Oct 29, 2014

Contributor

you can also change the default level

@sstok

sstok Oct 29, 2014

Contributor

you can also change the default level

@sstok

This comment has been minimized.

Show comment
Hide comment
@sstok

sstok Oct 29, 2014

Contributor

👍 for this feature.

Contributor

sstok commented Oct 29, 2014

👍 for this feature.

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Oct 29, 2014

Contributor

I've just got it! I squashed some commits.

@sstok Thanks for your help! I fixed some messages.

Contributor

fivestar commented Oct 29, 2014

I've just got it! I squashed some commits.

@sstok Thanks for your help! I fixed some messages.

@keradus keradus added the feature label Oct 29, 2014

@alterphp

This comment has been minimized.

Show comment
Hide comment
@alterphp

alterphp Oct 31, 2014

👍 great job !

👍 great job !

@keradus

This comment has been minimized.

Show comment
Hide comment
@keradus

keradus Nov 2, 2014

Member

Thank you @fivestar.

Member

keradus commented Nov 2, 2014

Thank you @fivestar.

@keradus keradus merged commit 23c07bb into FriendsOfPHP:master Nov 2, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

keradus added a commit that referenced this pull request Nov 2, 2014

feature #599 Fix `fix` command to handle `--fixers` option when conta…
…ins extra and excluding fixers (fivestar, keradus)

This PR was merged into the 1.0.x-dev branch.

Discussion
----------

Fix `fix` command to handle `--fixers` option when contains extra and excluding fixers

Currently, when `--fixers` option contains extra and excluding mixed filters such as `-eol_ending,concat_with_spaces`, excluding filter will be enabled, however, extra filter will not be enabled.

This PR fixes this behavior, so enable both type filters when mixed filters given.

----

`sample.php`

```php
<?php
echo 'foo'.'bar', PHP_EOL;

```

Current version: (`concat_with_spaces` is not enabled)

```
% php-cs-fixer fix -v --diff --fixers="-eol_ending,concat_with_spaces" --dry-run sample.php
   1) /home/fivestar/sample.php (eof_ending)
      ---------- begin diff ----------
      --- Original
      +++ New
      @@ @@
       <?php
       echo 'foo'.'bar', PHP_EOL;

      -

      ---------- end diff ----------
```

Fixed version: (`concat_with_spaces` is enabled)

```
% php-cs-fixer fix -v --diff --fixers="-eol_ending,concat_with_spaces" --dry-run sample.php
   1) /home/fivestar/sample.php (eof_ending, concat_with_spaces)
      ---------- begin diff ----------
      --- Original
      +++ New
      @@ @@
       <?php
      -echo 'foo'.'bar', PHP_EOL;
      -
      +echo 'foo' . 'bar', PHP_EOL;

      ---------- end diff ----------
```

Commits
-------

23c07bb FixersResolver - make class more state aware and enhance it's tests
e75c985 Fix README and some codes.
6876726 FixersResolver - simplify code
f3c966f Fix `fix` command to handle `--fixers` option when contains include and excluding fixers

@keradus keradus referenced this pull request Nov 3, 2014

Closed

Adding level to Config #433

@fivestar

This comment has been minimized.

Show comment
Hide comment
@fivestar

fivestar Nov 4, 2014

Contributor

Thank you too!!

Contributor

fivestar commented Nov 4, 2014

Thank you too!!

@fivestar fivestar deleted the fivestar:resolve-mixed-fixtures branch Nov 4, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment