From 16ec2e8878a3157c9e40c2c0dcf88fb7ef93cc3d Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 18 Nov 2017 09:20:38 +0100 Subject: [PATCH] Add explicit error messages when the programs cannot be found --- pretty | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pretty b/pretty index d370bf1..6eec3ce 100755 --- a/pretty +++ b/pretty @@ -29,13 +29,16 @@ $command = ''; // Detect which tool to run if (file_exists('phpcs.xml') || file_exists('phpcs.xml.dist')) { - echo "CodeSniffer configuration file found, running CodeSniffer\n"; + echo "PHP CodeSniffer configuration file found, running CodeSniffer\n"; + assertPhpCodeSnifferIsInstalled(); $command = $commands['phpcs']; } elseif (file_exists('.php_cs') || file_exists('.php_cs.dist')) { echo "PHP-CS-Fixer configuration file found, running PHP-CS-Fixer\n"; + assertPhpCsFixerIsInstalled(); $command = $commands['php-cs-fixer']; } else { echo "No configuration file found, running PHP CodeSniffer with PSR-2\n"; + assertPhpCodeSnifferIsInstalled(); $command = $commands['default']; } @@ -43,3 +46,31 @@ if (file_exists('phpcs.xml') || file_exists('phpcs.xml.dist')) { passthru($command, $exitCode); exit($exitCode); + +function commandExists($command) +{ + $return = shell_exec('which ' . escapeshellarg($command)); + return !empty($return); +} + +function assertPhpCodeSnifferIsInstalled() +{ + if (!commandExists('phpcs')) { + echo <<