Skip to content

Commit

Permalink
Use the - flag for checking STDIN (#10)
Browse files Browse the repository at this point in the history
* Use the `-` flag for checking STDIN

PHPCS offers the `-` flag on the end of the command and params to make it explicit, that we are going to read from STDIN instead of local files and directories. While omitting the `-` often works, it does not seem to work with empty files as our `cat empty.file | phpcs --report=json` seems to be hang in an infinite loop wainting for input data.

Adding `-` flag fixes the issue.
  • Loading branch information
david-binda authored and sirbrillig committed Aug 5, 2019
1 parent 2150269 commit 5c25625
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions PhpcsChanged/GitWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function isNewGitFile(string $gitFile, string $git, callable $executeCommand, ca
}

function getGitBasePhpcsOutput(string $gitFile, string $git, string $phpcs, string $phpcsStandardOption, callable $executeCommand, callable $debug): string {
$oldFilePhpcsOutputCommand = "${git} show HEAD:" . escapeshellarg($gitFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption;
$oldFilePhpcsOutputCommand = "${git} show HEAD:" . escapeshellarg($gitFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption . ' -';
$debug('running orig phpcs command:', $oldFilePhpcsOutputCommand);
$oldFilePhpcsOutput = $executeCommand($oldFilePhpcsOutputCommand);
if (! $oldFilePhpcsOutput) {
Expand All @@ -56,7 +56,7 @@ function getGitBasePhpcsOutput(string $gitFile, string $git, string $phpcs, stri
}

function getGitNewPhpcsOutput(string $gitFile, string $phpcs, string $cat, string $phpcsStandardOption, callable $executeCommand, callable $debug): string {
$newFilePhpcsOutputCommand = "{$cat} " . escapeshellarg($gitFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption;
$newFilePhpcsOutputCommand = "{$cat} " . escapeshellarg($gitFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption . ' -';
$debug('running new phpcs command:', $newFilePhpcsOutputCommand);
$newFilePhpcsOutput = $executeCommand($newFilePhpcsOutputCommand);
if (! $newFilePhpcsOutput) {
Expand Down
4 changes: 2 additions & 2 deletions PhpcsChanged/SvnWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function isNewSvnFile(string $svnFile, string $svn, callable $executeCommand, ca
}

function getSvnBasePhpcsOutput(string $svnFile, string $svn, string $phpcs, string $phpcsStandardOption, callable $executeCommand, callable $debug): string {
$oldFilePhpcsOutputCommand = "${svn} cat " . escapeshellarg($svnFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption;
$oldFilePhpcsOutputCommand = "${svn} cat " . escapeshellarg($svnFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption . ' -';
$debug('running orig phpcs command:', $oldFilePhpcsOutputCommand);
$oldFilePhpcsOutput = $executeCommand($oldFilePhpcsOutputCommand);
if (! $oldFilePhpcsOutput) {
Expand All @@ -53,7 +53,7 @@ function getSvnBasePhpcsOutput(string $svnFile, string $svn, string $phpcs, stri
}

function getSvnNewPhpcsOutput(string $svnFile, string $phpcs, string $cat, string $phpcsStandardOption, callable $executeCommand, callable $debug): string {
$newFilePhpcsOutputCommand = "{$cat} " . escapeshellarg($svnFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption;
$newFilePhpcsOutputCommand = "{$cat} " . escapeshellarg($svnFile) . " | {$phpcs} --report=json -q" . $phpcsStandardOption . ' -';
$debug('running new phpcs command:', $newFilePhpcsOutputCommand);
$newFilePhpcsOutput = $executeCommand($newFilePhpcsOutputCommand);
if (! $newFilePhpcsOutput) {
Expand Down

0 comments on commit 5c25625

Please sign in to comment.