@@ -18,6 +18,12 @@ Usage:
1818 n - Suppress warnings during the sniff run.
1919 x - Always exit zero regardless of sniff results.
2020
21+ Environment:
22+ CODESNIFFER_RUN_STANDARD - If set, overrides the name of the Coding
23+ Standard to use. The standard is assumed
24+ to be "installed" already.
25+ (Default: Loadsys)
26+
2127EOT
2228
2329 exit ${1:- 0} # Exit with code 0 unless an arg is passed to the method.
@@ -32,7 +38,8 @@ REPORT_DIR="${TMP_DIR}/code-sniffs"
3238FULL_REPORT_FILE=" ${REPORT_DIR} /report-full.txt"
3339SUMMARY_REPORT_FILE=" ${REPORT_DIR} /report-summary.txt"
3440
35- CODE_STANDARD=" vendor/cakephp/cakephp-codesniffer/CakePHP,vendor/loadsys/loadsys_codesniffer/Loadsys"
41+ CODE_STANDARD=${CODESNIFFER_RUN_STANDARD:- Loadsys}
42+ CODE_STANDARDS=(" vendor/cakephp/cakephp-codesniffer" " vendor/loadsys/loadsys_codesniffer" )
3643SNIFF_FOLDERS=(" ./src" " ./plugins" " ./tests" " ./config" " ./webroot" )
3744SNIFF_FAIL_CAUSES_SCRIPT_FAIL=0 # 0 = true. Script will exit with phpcs's return code.
3845
@@ -66,7 +73,27 @@ while getopts ":fhnx" opt; do
6673done
6774
6875
76+ # Make sure phpcs has the sniffs configured.
77+ INSTALLED_ALREADY=$( bin/phpcs --config-show | grep installed_paths )
78+ INSTALLED_ALREADY=${INSTALLED_ALREADY# installed_paths: }
79+ # echo "old = $INSTALLED_ALREADY"
80+
81+ for STANDARD in " ${CODE_STANDARDS[@]} " ; do
82+ if [[ ! $INSTALLED_ALREADY == * " $STANDARD " * ]]; then
83+ TO_INSTALL=" ${TO_INSTALL-} ,${STANDARD} "
84+ fi
85+ done
86+
87+ TO_INSTALL=${TO_INSTALL# ,}
88+ # echo "new = $TO_INSTALL"
89+ if [ -n " $TO_INSTALL " ] && [ " $TO_INSTALL " != " $INSTALLED_ALREADY " ]; then
90+ echo " ## Adding required coding standards installed paths."
91+ bin/phpcs --config-set installed_paths $TO_INSTALL > /dev/null
92+ fi
93+
94+
6995# Run the sniffs.
96+ echo " ## Executing code sniffer:"
7097bin/phpcs -ps $SUPPRESS_WARNINGS \
7198 --extensions=php \
7299 --standard=" $CODE_STANDARD " \
0 commit comments