Skip to content
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

Make php extensions configurable #83

Conversation

paolomainardi
Copy link
Contributor

No description provided.

@paolomainardi paolomainardi changed the title Add extensions support Make php extensions configurable Jul 11, 2017
@zdenekdrahos
Copy link
Member

Good idea to configure extensions 👍

I'd rather move the configuration to .phpqa.yml. I'd like to keep CLI options as simple as possible. Option --config is used for defining an advanced configuration. Is that ok for you?

src/Options.php Outdated
@@ -46,6 +49,7 @@ function ($dir) {
$this->isOutputPrinted = $this->isSavedToFiles ? $options['verbose'] : true;
$this->hasReport = $this->isSavedToFiles ? $options['report'] : false;
$this->configDir = $options['config'] ? $options['config'] : getcwd();
$this->extensions = isset($options['extensions']) ? $options['extensions'] : 'php';
Copy link
Member

Choose a reason for hiding this comment

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

isset is not necessary when you update copy-pasted code in OptionsTest
It's complicated to retrieve default options from comment, so they are copy-pasted in the test

Copy link
Member

Choose a reason for hiding this comment

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

You don't have to fix it. As I said in the comment, I would prefer configuration in .phpqa.yml.
You can take a look at adding configuration to .phpqa.yml.

@paolomainardi
Copy link
Contributor Author

@zdenekdrahos done, you can review it now.

Copy link
Member

@zdenekdrahos zdenekdrahos left a comment

Choose a reason for hiding this comment

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

Make extensions configurable globally. Then only three lines should be changed in CodeAnalysisTasks

README.md Outdated
@@ -139,6 +139,7 @@ For full documentation please visit [eko3alpha/docker-phpqa](https://hub.docker.
| ~~`phpqa --analyzedDir ./`~~ | Deprecated in **v1.8** in favor of `--analyzedDirs` |
| `phpqa --ignoredDirs build,vendor` | Ignore directories |
| `phpqa --ignoredFiles RoboFile.php` | Ignore files |
| `phpqa --extensions php,inc,module` | Run only on selected extensions (default: ``php`` |
Copy link
Member

Choose a reason for hiding this comment

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

Old comment, extensions should be documented in advanced configuration

.phpqa.yml Outdated
@@ -11,6 +11,8 @@ phpcs:
checkstyle: checkstyle.xml
# you can include custom reports (https://github.com/wikidi/codesniffer/blob/master/reports/wikidi/Summary.php#L39)
# ./vendor/owner/package/src/MySummaryReport.php: phpcs-summary.html
extensions:
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't define extensions for each tool, but only once (just like you had it in --extensions).

extensions:
    - php

'standard' => $standard,
$this->options->ignore->phpcs(),
$this->options->getAnalyzedDirs(' '),
);
if (!empty($extensions)) {
Copy link
Member

Choose a reason for hiding this comment

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

There is a lot of duplication in loading extensions. Extracting the code to Config might be a good idea.

        $args = array(
            'extensions' => $this->config->csv('extensions'),
        );

It would be great to have tests that show behavior what happens, when extensions is array, string, ...
I would ignore cases when extensions are empty. It's required configuration, so we don't have to be too defensive.

@paolomainardi
Copy link
Contributor Author

@zdenekdrahos thanks for the review, you can see latest changes now.

fix notice
refactoring using .phpqa.yml
move extensions to global namespace, add test, add logic to Config class to parse the array
fix metrics
@paolomainardi paolomainardi force-pushed the feature/make-php-extensions-configurable branch from 3afb72f to 33a7974 Compare July 13, 2017 12:06
Copy link
Member

@zdenekdrahos zdenekdrahos left a comment

Choose a reason for hiding this comment

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

A couple small fixes and it's ready to merge.
Good job 👍

@@ -281,15 +281,17 @@ private function buildPhpcs(RunningTool $tool, array $installedStandards)

private function pdepend()
{
return array(
$opts = array(
Copy link
Member

Choose a reason for hiding this comment

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

Please revert a return. The temporary variable is useless.

@@ -56,6 +58,26 @@ public function testThrowExceptionWhenFileDoesNotExist()
$config->path('phpcs.standard');
}

public function testConfigCsvArray()
Copy link
Member

Choose a reason for hiding this comment

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

One test is good enough if you move php,inc,module to tests/Config/.phpqa.yml.

  • Array format is tested in default config.
  • Hardcoding expected value in the test is fine (not perfect, but the test is more readable without parsing YAML).

I guess that removing YAML::parse should help to pass Travis.ci

@@ -21,7 +21,7 @@ If you ever tried to get ignoring directories to work then you know what I mean.
CLI tools are cool because you can analyze any directory or file.
Copy link
Member

Choose a reason for hiding this comment

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

I see only whitespace changes. Revert changes if you don't plan to document extensions in advanced configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is has been automatically added by sublime, it is just a whitespace, i guess it quite safe to keep it.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that it is a safe change. But should it be a part of "Make PHP extensions configurable" commit, if nothing else is changed?

You can keep it, but add documentation for extensions (newline after README.md#L201). Thanks

[extensions](https://github.com/EdgedesignCZ/phpqa/blob/master/.phpqa.yml) | File extensions | `[php]` | List of PHP file extensions |

@paolomainardi
Copy link
Contributor Author

@zdenekdrahos done

@@ -56,6 +56,15 @@ public function testThrowExceptionWhenFileDoesNotExist()
$config->path('phpcs.standard');
}

public function testConfigCsvString()
Copy link
Member

Choose a reason for hiding this comment

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

Please load tests/Config/.phpqa.yml and remove tests/Config/data/custom-extensions-string/.phpqa.yml.

$config->loadCustomConfig(__DIR__);

isNonEmptyString assert is not necessary, equalTo catches all types of invalid values. When the test fails I would rather see, that expected value is php,inc,module instead of non-empty string. But that's a minor issue, you can leave it that way if you think it's better.

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

@@ -21,7 +21,7 @@ If you ever tried to get ignoring directories to work then you know what I mean.
CLI tools are cool because you can analyze any directory or file.
Copy link
Member

Choose a reason for hiding this comment

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

I agree that it is a safe change. But should it be a part of "Make PHP extensions configurable" commit, if nothing else is changed?

You can keep it, but add documentation for extensions (newline after README.md#L201). Thanks

[extensions](https://github.com/EdgedesignCZ/phpqa/blob/master/.phpqa.yml) | File extensions | `[php]` | List of PHP file extensions |

@paolomainardi
Copy link
Contributor Author

@zdenekdrahos done 👍

@zdenekdrahos zdenekdrahos merged commit 506d340 into EdgedesignCZ:master Jul 13, 2017
@zdenekdrahos
Copy link
Member

I don't like squash. But I did it because of general commit message "code review" in history. I hope that's okay.

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

Successfully merging this pull request may close these issues.

2 participants