From 5c25625974d4f06aa72ea88e787b6eaac4edc7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bi=C5=88ovec?= Date: Mon, 5 Aug 2019 22:33:15 +0200 Subject: [PATCH] Use the `-` flag for checking STDIN (#10) * 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. --- PhpcsChanged/GitWorkflow.php | 4 ++-- PhpcsChanged/SvnWorkflow.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PhpcsChanged/GitWorkflow.php b/PhpcsChanged/GitWorkflow.php index 33b869e..20eecbc 100644 --- a/PhpcsChanged/GitWorkflow.php +++ b/PhpcsChanged/GitWorkflow.php @@ -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) { @@ -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) { diff --git a/PhpcsChanged/SvnWorkflow.php b/PhpcsChanged/SvnWorkflow.php index 3237264..5688a3f 100644 --- a/PhpcsChanged/SvnWorkflow.php +++ b/PhpcsChanged/SvnWorkflow.php @@ -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) { @@ -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) {