Skip to content

Commit 721f53e

Browse files
committed
Merge pull request #53 from loadsys/b/codesniffer
Removed Console/Shell Path - Updated to Just {src}/Shell
2 parents 76a241d + b232968 commit 721f53e

18 files changed

Lines changed: 72 additions & 61 deletions

cache-clear

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Usage:
1919
2020
EOT
2121

22-
exit 0
22+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2323
}
2424
if [ "$1" = '-h' ]; then
2525
usage

codesniffer-run

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,77 @@ ${0##*/}
1111
to the standard output.
1212
1313
Usage:
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
2021
EOT
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.
2828
umask a+rw
2929

3030
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
31-
BIN_DIR="${DIR}/bin"
3231
TMP_DIR="${DIR}/tmp"
33-
SRC_DIR="${DIR}/src"
3432
REPORT_DIR="${TMP_DIR}/code-sniffs"
3533
FULL_REPORT_FILE="${REPORT_DIR}/report-full.txt"
3634
SUMMARY_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+
6777
SNIFF_RESULT=$?
6878

6979
if [ $SAVE_REPORTS -eq 0 ]; then
7080
echo "## Full report created at: ${FULL_REPORT_FILE}"
7181
echo "## Summary report created at: ${SUMMARY_REPORT_FILE}"
7282
fi
7383

84+
7485
# Exit based on whether sniff fails should count as a "failure".
7586
if [ $SNIFF_FAIL_CAUSES_SCRIPT_FAIL -eq 0 ]; then
7687
exit $SNIFF_RESULT

composer-install

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ${0##*/}
1111
the presence or absence of a composer.json file. Can be safely
1212
called even if these items are missing (with the result being
1313
essentially a no-op and >0 exit code.)
14-
14+
1515
There is a certain amount of irony in this script being
1616
included in a composer package, since you would have had to
1717
already run 'composer install' in order to have access to this
@@ -26,7 +26,7 @@ Usage:
2626
2727
EOT
2828

29-
exit 0
29+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
3030
}
3131
if [ "$1" = '-h' ]; then
3232
usage

db-login

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Usage:
1717
1818
EOT
1919

20-
exit 0
20+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2121
}
2222
if [ "$1" = '-h' ]; then
2323
usage

db-sample-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Usage:
1919
2020
EOT
2121

22-
exit 0
22+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2323
}
2424
if [ "$1" = '-h' ]; then
2525
usage

docs-generate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Usage:
1717
1818
EOT
1919

20-
exit 0
20+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2121
}
2222
if [ "$1" = '-h' ]; then
2323
usage

email

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Usage:
1919
2020
EOT
2121

22-
exit 0
22+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2323
}
2424
if [ "$1" = '-h' ]; then
2525
usage

git-currentbranch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Environment Variables:
2121
2222
EOT
2323

24-
exit 0
24+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2525
}
2626
if [ "$1" = '-h' ]; then
2727
usage

git-hook-workingcopychange

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Environment Variables:
3434
3535
EOT
3636

37-
exit 0
37+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
3838
}
3939
if [ "$1" = '-h' ]; then
4040
usage

git-localchanges

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Usage:
1717
1818
EOT
1919

20-
exit 0
20+
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
2121
}
2222
if [ "$1" = '-h' ]; then
2323
usage

0 commit comments

Comments
 (0)