@@ -29,17 +29,48 @@ $command = '';
29
29
30
30
// Detect which tool to run
31
31
if (file_exists ('phpcs.xml ' ) || file_exists ('phpcs.xml.dist ' )) {
32
- echo "CodeSniffer configuration file found, running CodeSniffer \n" ;
32
+ echo "PHP CodeSniffer configuration file found, running CodeSniffer \n" ;
33
+ assertPhpCodeSnifferIsInstalled ();
33
34
$ command = $ commands ['phpcs ' ];
34
35
} elseif (file_exists ('.php_cs ' ) || file_exists ('.php_cs.dist ' )) {
35
36
echo "PHP-CS-Fixer configuration file found, running PHP-CS-Fixer \n" ;
37
+ assertPhpCsFixerIsInstalled ();
36
38
$ command = $ commands ['php-cs-fixer ' ];
37
39
} else {
38
40
echo "No configuration file found, running PHP CodeSniffer with PSR-2 \n" ;
41
+ assertPhpCodeSnifferIsInstalled ();
39
42
$ command = $ commands ['default ' ];
40
43
}
41
44
42
45
// Run the analysis
43
46
passthru ($ command , $ exitCode );
44
47
45
48
exit ($ exitCode );
49
+
50
+ function commandExists ($ command )
51
+ {
52
+ $ return = shell_exec ('which ' . escapeshellarg ($ command ));
53
+ return !empty ($ return );
54
+ }
55
+
56
+ function assertPhpCodeSnifferIsInstalled ()
57
+ {
58
+ if (!commandExists ('phpcs ' )) {
59
+ echo <<<INSTRUCTIONS
60
+ ERROR: PHP CodeSniffer does not seem to be installed because the 'phpcs' program cannot be found.
61
+ You can install it by following the instructions here: https://github.com/squizlabs/PHP_CodeSniffer#installation
62
+ INSTRUCTIONS ;
63
+ exit (1 );
64
+ }
65
+ }
66
+
67
+ function assertPhpCsFixerIsInstalled ()
68
+ {
69
+ if (!commandExists ('php-cs-fixer ' )) {
70
+ echo <<<INSTRUCTIONS
71
+ ERROR: PHP-CS-Fixer does not seem to be installed because the 'php-cs-fixer' program cannot be found.
72
+ You can install it by following the instructions here: https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation
73
+ INSTRUCTIONS ;
74
+ exit (1 );
75
+ }
76
+ }
0 commit comments