1717use PHP_CodeSniffer \Exceptions \DeepExitException ;
1818use PHP_CodeSniffer \Exceptions \RuntimeException ;
1919use PHP_CodeSniffer \Util \Common ;
20+ use PHP_CodeSniffer \Util \ExitCode ;
2021use PHP_CodeSniffer \Util \Help ;
2122use PHP_CodeSniffer \Util \Standards ;
2223
@@ -678,10 +679,10 @@ public function processShortArgument($arg, $pos)
678679 case 'h ' :
679680 case '? ' :
680681 $ this ->printUsage ();
681- throw new DeepExitException ('' , 0 );
682+ throw new DeepExitException ('' , ExitCode:: OKAY );
682683 case 'i ' :
683684 $ output = Standards::prepareInstalledStandardsForDisplay ().PHP_EOL ;
684- throw new DeepExitException ($ output , 0 );
685+ throw new DeepExitException ($ output , ExitCode:: OKAY );
685686 case 'v ' :
686687 if ($ this ->quiet === true ) {
687688 // Ignore when quiet mode is enabled.
@@ -747,7 +748,7 @@ public function processShortArgument($arg, $pos)
747748 if ($ changed === false && ini_get ($ ini [0 ]) !== $ ini [1 ]) {
748749 $ error = sprintf ('ERROR: Ini option "%s" cannot be changed at runtime. ' , $ ini [0 ]).PHP_EOL ;
749750 $ error .= $ this ->printShortUsage (true );
750- throw new DeepExitException ($ error , 3 );
751+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
751752 }
752753 break ;
753754 case 'n ' :
@@ -789,11 +790,11 @@ public function processLongArgument($arg, $pos)
789790 switch ($ arg ) {
790791 case 'help ' :
791792 $ this ->printUsage ();
792- throw new DeepExitException ('' , 0 );
793+ throw new DeepExitException ('' , ExitCode:: OKAY );
793794 case 'version ' :
794795 $ output = 'PHP_CodeSniffer version ' .self ::VERSION .' ( ' .self ::STABILITY .') ' ;
795796 $ output .= 'by Squiz and PHPCSStandards ' .PHP_EOL ;
796- throw new DeepExitException ($ output , 0 );
797+ throw new DeepExitException ($ output , ExitCode:: OKAY );
797798 case 'colors ' :
798799 if (isset ($ this ->overriddenDefaults ['colors ' ]) === true ) {
799800 break ;
@@ -840,7 +841,7 @@ public function processLongArgument($arg, $pos)
840841 ) {
841842 $ error = 'ERROR: Setting a config option requires a name and value ' .PHP_EOL .PHP_EOL ;
842843 $ error .= $ this ->printShortUsage (true );
843- throw new DeepExitException ($ error , 3 );
844+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
844845 }
845846
846847 $ key = $ this ->cliArgs [($ pos + 1 )];
@@ -850,7 +851,7 @@ public function processLongArgument($arg, $pos)
850851 try {
851852 $ this ->setConfigData ($ key , $ value );
852853 } catch (Exception $ e ) {
853- throw new DeepExitException ($ e ->getMessage ().PHP_EOL , 3 );
854+ throw new DeepExitException ($ e ->getMessage ().PHP_EOL , ExitCode:: PROCESS_ERROR );
854855 }
855856
856857 $ output = 'Using config file: ' .self ::$ configDataFile .PHP_EOL .PHP_EOL ;
@@ -860,12 +861,12 @@ public function processLongArgument($arg, $pos)
860861 } else {
861862 $ output .= "Config value \"$ key \" updated successfully; old value was \"$ current \"" .PHP_EOL ;
862863 }
863- throw new DeepExitException ($ output , 0 );
864+ throw new DeepExitException ($ output , ExitCode:: OKAY );
864865 case 'config-delete ' :
865866 if (isset ($ this ->cliArgs [($ pos + 1 )]) === false ) {
866867 $ error = 'ERROR: Deleting a config option requires the name of the option ' .PHP_EOL .PHP_EOL ;
867868 $ error .= $ this ->printShortUsage (true );
868- throw new DeepExitException ($ error , 3 );
869+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
869870 }
870871
871872 $ output = 'Using config file: ' .self ::$ configDataFile .PHP_EOL .PHP_EOL ;
@@ -878,24 +879,24 @@ public function processLongArgument($arg, $pos)
878879 try {
879880 $ this ->setConfigData ($ key , null );
880881 } catch (Exception $ e ) {
881- throw new DeepExitException ($ e ->getMessage ().PHP_EOL , 3 );
882+ throw new DeepExitException ($ e ->getMessage ().PHP_EOL , ExitCode:: PROCESS_ERROR );
882883 }
883884
884885 $ output .= "Config value \"$ key \" removed successfully; old value was \"$ current \"" .PHP_EOL ;
885886 }
886- throw new DeepExitException ($ output , 0 );
887+ throw new DeepExitException ($ output , ExitCode:: OKAY );
887888 case 'config-show ' :
888889 $ data = self ::getAllConfigData ();
889890 $ output = 'Using config file: ' .self ::$ configDataFile .PHP_EOL .PHP_EOL ;
890891 $ output .= $ this ->prepareConfigDataForDisplay ($ data );
891- throw new DeepExitException ($ output , 0 );
892+ throw new DeepExitException ($ output , ExitCode:: OKAY );
892893 case 'runtime-set ' :
893894 if (isset ($ this ->cliArgs [($ pos + 1 )]) === false
894895 || isset ($ this ->cliArgs [($ pos + 2 )]) === false
895896 ) {
896897 $ error = 'ERROR: Setting a runtime config option requires a name and value ' .PHP_EOL .PHP_EOL ;
897898 $ error .= $ this ->printShortUsage (true );
898- throw new DeepExitException ($ error , 3 );
899+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
899900 }
900901
901902 $ key = $ this ->cliArgs [($ pos + 1 )];
@@ -946,7 +947,7 @@ public function processLongArgument($arg, $pos)
946947 if (is_dir ($ dir ) === false ) {
947948 $ error = 'ERROR: The specified cache file path " ' .$ this ->cacheFile .'" points to a non-existent directory ' .PHP_EOL .PHP_EOL ;
948949 $ error .= $ this ->printShortUsage (true );
949- throw new DeepExitException ($ error , 3 );
950+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
950951 }
951952
952953 if ($ dir === '. ' ) {
@@ -972,7 +973,7 @@ public function processLongArgument($arg, $pos)
972973 if (is_dir ($ this ->cacheFile ) === true ) {
973974 $ error = 'ERROR: The specified cache file path " ' .$ this ->cacheFile .'" is a directory ' .PHP_EOL .PHP_EOL ;
974975 $ error .= $ this ->printShortUsage (true );
975- throw new DeepExitException ($ error , 3 );
976+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
976977 }
977978 } else if (substr ($ arg , 0 , 10 ) === 'bootstrap= ' ) {
978979 $ files = explode (', ' , substr ($ arg , 10 ));
@@ -982,7 +983,7 @@ public function processLongArgument($arg, $pos)
982983 if ($ path === false ) {
983984 $ error = 'ERROR: The specified bootstrap file " ' .$ file .'" does not exist ' .PHP_EOL .PHP_EOL ;
984985 $ error .= $ this ->printShortUsage (true );
985- throw new DeepExitException ($ error , 3 );
986+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
986987 }
987988
988989 $ bootstrap [] = $ path ;
@@ -996,7 +997,7 @@ public function processLongArgument($arg, $pos)
996997 if ($ path === false ) {
997998 $ error = 'ERROR: The specified file list " ' .$ fileList .'" does not exist ' .PHP_EOL .PHP_EOL ;
998999 $ error .= $ this ->printShortUsage (true );
999- throw new DeepExitException ($ error , 3 );
1000+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
10001001 }
10011002
10021003 $ files = file ($ path );
@@ -1038,7 +1039,7 @@ public function processLongArgument($arg, $pos)
10381039 if (is_dir ($ dir ) === false ) {
10391040 $ error = 'ERROR: The specified report file path " ' .$ this ->reportFile .'" points to a non-existent directory ' .PHP_EOL .PHP_EOL ;
10401041 $ error .= $ this ->printShortUsage (true );
1041- throw new DeepExitException ($ error , 3 );
1042+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
10421043 }
10431044
10441045 $ this ->reportFile = $ dir .'/ ' .basename ($ this ->reportFile );
@@ -1049,7 +1050,7 @@ public function processLongArgument($arg, $pos)
10491050 if (is_dir ($ this ->reportFile ) === true ) {
10501051 $ error = 'ERROR: The specified report file path " ' .$ this ->reportFile .'" is a directory ' .PHP_EOL .PHP_EOL ;
10511052 $ error .= $ this ->printShortUsage (true );
1052- throw new DeepExitException ($ error , 3 );
1053+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
10531054 }
10541055 } else if (substr ($ arg , 0 , 13 ) === 'report-width= ' ) {
10551056 if (isset ($ this ->overriddenDefaults ['reportWidth ' ]) === true ) {
@@ -1080,7 +1081,7 @@ public function processLongArgument($arg, $pos)
10801081 if (is_dir ($ this ->basepath ) === false ) {
10811082 $ error = 'ERROR: The specified basepath " ' .$ this ->basepath .'" points to a non-existent directory ' .PHP_EOL .PHP_EOL ;
10821083 $ error .= $ this ->printShortUsage (true );
1083- throw new DeepExitException ($ error , 3 );
1084+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
10841085 }
10851086 } else if ((substr ($ arg , 0 , 7 ) === 'report= ' || substr ($ arg , 0 , 7 ) === 'report- ' )) {
10861087 $ reports = [];
@@ -1101,15 +1102,15 @@ public function processLongArgument($arg, $pos)
11011102 if (is_dir ($ dir ) === false ) {
11021103 $ error = 'ERROR: The specified ' .$ report .' report file path " ' .$ output .'" points to a non-existent directory ' .PHP_EOL .PHP_EOL ;
11031104 $ error .= $ this ->printShortUsage (true );
1104- throw new DeepExitException ($ error , 3 );
1105+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
11051106 }
11061107
11071108 $ output = $ dir .'/ ' .basename ($ output );
11081109
11091110 if (is_dir ($ output ) === true ) {
11101111 $ error = 'ERROR: The specified ' .$ report .' report file path " ' .$ output .'" is a directory ' .PHP_EOL .PHP_EOL ;
11111112 $ error .= $ this ->printShortUsage (true );
1112- throw new DeepExitException ($ error , 3 );
1113+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
11131114 }
11141115 }//end if
11151116 }//end if
@@ -1167,7 +1168,7 @@ public function processLongArgument($arg, $pos)
11671168 $ error .= 'PHP_CodeSniffer >= 4.0 only supports scanning PHP files. ' .PHP_EOL ;
11681169 $ error .= 'Received: ' .substr ($ arg , 11 ).PHP_EOL .PHP_EOL ;
11691170 $ error .= $ this ->printShortUsage (true );
1170- throw new DeepExitException ($ error , 3 );
1171+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
11711172 }
11721173 }
11731174
@@ -1258,7 +1259,7 @@ public function processLongArgument($arg, $pos)
12581259 $ validOptions
12591260 );
12601261 $ error .= $ this ->printShortUsage (true );
1261- throw new DeepExitException ($ error , 3 );
1262+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
12621263 }
12631264
12641265 $ this ->generator = $ this ->validGenerators [$ lowerCaseGeneratorName ];
@@ -1384,7 +1385,7 @@ static function ($carry, $item) {
13841385
13851386 $ error .= PHP_EOL ;
13861387 $ error .= $ this ->printShortUsage (true );
1387- throw new DeepExitException (ltrim ($ error ), 3 );
1388+ throw new DeepExitException (ltrim ($ error ), ExitCode:: PROCESS_ERROR );
13881389 }
13891390
13901391 return $ sniffs ;
@@ -1413,7 +1414,7 @@ public function processUnknownArgument($arg, $pos)
14131414
14141415 $ error = "ERROR: option \"$ arg \" not known " .PHP_EOL .PHP_EOL ;
14151416 $ error .= $ this ->printShortUsage (true );
1416- throw new DeepExitException ($ error , 3 );
1417+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
14171418 }
14181419
14191420 $ this ->processFilePath ($ arg );
@@ -1444,7 +1445,7 @@ public function processFilePath($path)
14441445
14451446 $ error = 'ERROR: The file " ' .$ path .'" does not exist. ' .PHP_EOL .PHP_EOL ;
14461447 $ error .= $ this ->printShortUsage (true );
1447- throw new DeepExitException ($ error , 3 );
1448+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
14481449 } else {
14491450 // Can't modify the files array directly because it's not a real
14501451 // class member, so need to use this little get/modify/set trick.
@@ -1652,7 +1653,7 @@ public function setConfigData($key, $value, $temp=false)
16521653 && is_writable ($ configFile ) === false
16531654 ) {
16541655 $ error = 'ERROR: Config file ' .$ configFile .' is not writable ' .PHP_EOL .PHP_EOL ;
1655- throw new DeepExitException ($ error , 3 );
1656+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
16561657 }
16571658 }//end if
16581659
@@ -1673,7 +1674,7 @@ public function setConfigData($key, $value, $temp=false)
16731674
16741675 if (file_put_contents ($ configFile , $ output ) === false ) {
16751676 $ error = 'ERROR: Config file ' .$ configFile .' could not be written ' .PHP_EOL .PHP_EOL ;
1676- throw new DeepExitException ($ error , 3 );
1677+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
16771678 }
16781679
16791680 self ::$ configDataFile = $ configFile ;
@@ -1731,7 +1732,7 @@ public static function getAllConfigData()
17311732
17321733 if (Common::isReadable ($ configFile ) === false ) {
17331734 $ error = 'ERROR: Config file ' .$ configFile .' is not readable ' .PHP_EOL .PHP_EOL ;
1734- throw new DeepExitException ($ error , 3 );
1735+ throw new DeepExitException ($ error , ExitCode:: PROCESS_ERROR );
17351736 }
17361737
17371738 include $ configFile ;
0 commit comments