Skip to content

Commit

Permalink
Update to Drupal Coder 8.3.x. (#3132)
Browse files Browse the repository at this point in the history
Fixes #2289 
--------

Changes proposed:
---------
(What are you proposing we change?)

- Update composer contraint on Drupal Coder newest release (8.3.1 as of this date)
- Update composer constraint on squizlabs/php_codesniffer to 3.0.1 (matching Coder)
- Remove the use of a bootstrap file with PHPCS. File paths that are not allowed by filesets won't be sniffed by default.
- Add a tests:phpcs:sniff:modified command to sniff unstaged modified or added files in repo for convenience.
  • Loading branch information
wu-edward authored and lcatlett committed Nov 1, 2018
1 parent 4a8e40e commit fccd0d0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 81 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -25,14 +25,14 @@
"dflydev/dot-access-data": "^1.1.0",
"doctrine/common": "^2.5",
"doctrine/inflector": "~1.1.0",
"drupal/coder": "^8.2.11",
"drupal/coder": "^8.3.1",
"drush/drush": "^9.4.0",
"grasmash/drupal-security-warning": "^1.0.0",
"grasmash/yaml-cli": "^1.0.0",
"grasmash/yaml-expander": "^1.2.0",
"oomphinc/composer-installers-extender": "^1.1",
"phpunit/phpunit": "^4.8|^6.5",
"squizlabs/php_codesniffer": "^2.7",
"squizlabs/php_codesniffer": "^3.0.1",
"symfony/console": "^3.4.0",
"symfony/twig-bridge": "^3.3",
"symfony/yaml": "^3.2.8",
Expand Down
73 changes: 45 additions & 28 deletions src/Robo/Commands/Validate/PhpcsCommand.php
Expand Up @@ -67,46 +67,63 @@ public function sniffFileList($file_list) {
$this->say("Sniffing directories containing changed files...");
$files = explode("\n", $file_list);
$files = array_filter($files);
$exit_code = $this->doSniffFileList($files);
if ($files) {
$temp_path = $this->getConfigValue('repo.root') . '/tmp/phpcs-fileset';
$this->taskWriteToFile($temp_path)
->lines($files)
->run();
$arguments = "--file-list='$temp_path' -l";
$exit_code = $this->doSniff($arguments);
unlink($temp_path);

return $exit_code;
return $exit_code;
}

return 0;
}

/**
* Executes PHP Code Sniffer against an array of files.
* Executes PHPCS against (unstaged) modified or untracked files in repo.
*
* @param array $files
* A flat array of absolute file paths.
* This command will execute PHP Codesniffer against modified/untracked files
* if those files are a subset of the phpcs.filesets filesets.
*
* @command tests:phpcs:sniff:modified
* @aliases tpsm
*
* @return int
*/
protected function doSniffFileList(array $files) {
if ($files) {
$temp_path = $this->getConfigValue('repo.root') . '/tmp/phpcs-fileset';
$this->taskWriteToFile($temp_path)
->lines($files)
->run();
public function sniffModified() {
$this->say("Sniffing modified and untracked files in repo...");
$arguments = "--filter=gitmodified " . $this->getConfigValue('repo.root');
$exit_code = $this->doSniff($arguments);

$bin = $this->getConfigValue('composer.bin') . '/phpcs';
$bootstrap = __DIR__ . "/phpcs-validate-files-bootstrap.php";
$command = "'$bin' --file-list='$temp_path' --bootstrap='$bootstrap' -l";
if ($this->output()->isVerbose()) {
$command .= ' -v';
}
elseif ($this->output()->isVeryVerbose()) {
$command .= ' -vv';
}
$result = $this->taskExecStack()
->exec($command)
->printMetadata(FALSE)
->run();

unlink($temp_path);
return $exit_code;
}

return $result->getExitCode();
/**
* Executes PHP Code Sniffer using specified options/arguments.
*
* @param string $arguments
* The command arguments/options.
*
* @return int
*/
protected function doSniff($arguments) {
$bin = $this->getConfigValue('composer.bin') . '/phpcs';
$command = "'$bin' $arguments";
if ($this->output()->isVerbose()) {
$command .= ' -v';
}
elseif ($this->output()->isVeryVerbose()) {
$command .= ' -vv';
}
$result = $this->taskExecStack()
->exec($command)
->printMetadata(FALSE)
->run();

return 0;
return $result->getExitCode();
}

}
50 changes: 0 additions & 50 deletions src/Robo/Commands/Validate/phpcs-validate-files-bootstrap.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/phpunit/Blt/PhpCsTest.php
Expand Up @@ -18,7 +18,7 @@ class PhpCsTest extends BltTestBase {
* @dataProvider testPhpCsFilesBootstrapProvider
*/
public function testPhpCsFilesBootstrap($filename, $needle, $contains) {
$process = new Process("./vendor/bin/phpcs $filename --bootstrap=src/Robo/Commands/Validate/phpcs-validate-files-bootstrap.php -v");
$process = new Process("./vendor/bin/phpcs -v $filename");
$process->setWorkingDirectory($this->bltDirectory);
$process->run();
$output = $process->getOutput();
Expand Down

0 comments on commit fccd0d0

Please sign in to comment.