@@ -11,66 +11,77 @@ ${0##*/}
1111 to the standard output.
1212
1313Usage:
14- bin/${0##*/ } [save reports?]
15-
16- Specify 'y' as the first argument to save reports in the tmp directory,
17- else full and summary reports are generated but not saved to a file.
14+ bin/${0##*/ } [-f|h|n|x]
1815
16+ f - Write full and summary report out to files.
17+ h - Print this help information.
18+ n - Suppress warnings during the sniff run.
19+ x - Always exit zero regardless of sniff results.
1920
2021EOT
2122
22- exit 0
23+ exit ${1 :- 0} # Exit with code 0 unless an arg is passed to the method.
2324}
24- if [ " $1 " = ' -h' ]; then
25- usage
26- fi
2725
26+
27+ # Set up local variables.
2828umask a+rw
2929
3030DIR=" $( cd -P " $( dirname " $0 " ) " /.. > /dev/null 2>&1 && pwd ) "
31- BIN_DIR=" ${DIR} /bin"
3231TMP_DIR=" ${DIR} /tmp"
33- SRC_DIR=" ${DIR} /src"
3432REPORT_DIR=" ${TMP_DIR} /code-sniffs"
3533FULL_REPORT_FILE=" ${REPORT_DIR} /report-full.txt"
3634SUMMARY_REPORT_FILE=" ${REPORT_DIR} /report-summary.txt"
3735
38- CODE_STANDARD=" vendor/loadsys/loadsys_codesniffer/Loadsys"
39- SNIFF_FOLDERS=(" ${SRC_DIR} /Controller " " ${SRC_DIR} /Model " " ${SRC_DIR} /View " " ${SRC_DIR} /Lib " " ${SRC_DIR} /Console/Shell " )
40- SNIFF_FAIL_CAUSES_SCRIPT_FAIL=1 # 1 = false. This script will therefore always exit 0 .
36+ CODE_STANDARD=" vendor/cakephp/cakephp-codesniffer/CakePHP,vendor/ loadsys/loadsys_codesniffer/Loadsys"
37+ SNIFF_FOLDERS=(" ./src " " ./plugins " " ./tests " " ./config " " ./webroot " )
38+ SNIFF_FAIL_CAUSES_SCRIPT_FAIL=0 # 0 = true. Script will exit with phpcs's return code .
4139
42- # Bail out if phpcs isn't available to us.
43- PHPCS=" $( which phpcs ) "
44- if [ $? -gt 0 ]; then
45- PHPCS=" $BIN_DIR /phpcs"
46- test -x $PHPCS
47- fi
48- if [ $? -gt 0 ]; then
49- echo " !! The 'phpcs' command was not found on this system."
50- echo " "
51- exit 1
52- fi
53- echo " ## Found phpcs at: ${PHPCS} "
40+ SAVE_REPORTS=1 # 1 = false. DON'T save reports when no args provided.
41+ COVERAGE=" --report-full --report-summary"
42+ SUPPRESS_WARNINGS=" "
5443
55- if [ -z " $1 " ]; then
56- echo " ## Printing reports..."
57- SAVE_REPORTS=1 # 1 = false. DON'T save reports when no args provided.
58- COVERAGE=" --report-full --report-summary"
59- else
60- echo " ## Saving reports..."
61- SAVE_REPORTS=0 # 0 = true. Save reports to files, not print to screen.
62- COVERAGE=" --report-full=${FULL_REPORT_FILE} --report-summary=${SUMMARY_REPORT_FILE} "
63- mkdir -p " $REPORT_DIR "
64- fi
6544
66- " $PHPCS " -p --extensions=php --standard=" $CODE_STANDARD " ${COVERAGE} ${SNIFF_FOLDERS[@]}
45+ # Process command line options.
46+ while getopts " :fhnx" opt; do
47+ case $opt in
48+ f)
49+ SAVE_REPORTS=0 # 0 = true. Save reports to files, not print to screen.
50+ COVERAGE=" --report-full=${FULL_REPORT_FILE} --report-summary=${SUMMARY_REPORT_FILE} "
51+ mkdir -p " $REPORT_DIR "
52+ ;;
53+ h)
54+ usage 0
55+ ;;
56+ n)
57+ SUPPRESS_WARNINGS=" -n"
58+ ;;
59+ x)
60+ SNIFF_FAIL_CAUSES_SCRIPT_FAIL=1 # 1 = false. Always exit 0;
61+ ;;
62+ \? )
63+ echo " Invalid option: -$OPTARG " >&2
64+ usage 1
65+ ;;
66+ esac
67+ done
68+
69+
70+ # Run the sniffs.
71+ bin/phpcs -p $SUPPRESS_WARNINGS \
72+ --extensions=php \
73+ --standard=" $CODE_STANDARD " \
74+ ${COVERAGE} \
75+ ${SNIFF_FOLDERS[@]}
76+
6777SNIFF_RESULT=$?
6878
6979if [ $SAVE_REPORTS -eq 0 ]; then
7080 echo " ## Full report created at: ${FULL_REPORT_FILE} "
7181 echo " ## Summary report created at: ${SUMMARY_REPORT_FILE} "
7282fi
7383
84+
7485# Exit based on whether sniff fails should count as a "failure".
7586if [ $SNIFF_FAIL_CAUSES_SCRIPT_FAIL -eq 0 ]; then
7687 exit $SNIFF_RESULT
0 commit comments