Skip to content

Commit

Permalink
PHPCF option in php linter
Browse files Browse the repository at this point in the history
  • Loading branch information
laemtl committed Jul 21, 2020
1 parent 3ce0b19 commit 66b637a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"lint:javascript": "./test/run-js-linter.sh",
"lintfix:javascript": "eslint --fix --ext .js, jsx modules",
"lint:php": "./test/run-php-linter.sh",
"lintfix:php": "./test/run-php-linter.sh -f",
"tests:static": "make checkstatic",
"lint:shell": "./test/run-shell-linter.sh",
"tests:unit": "./test/dockerized-unit-tests.sh",
Expand Down
69 changes: 60 additions & 9 deletions test/run-php-linter.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

has_param() {
local term="$1"
shift
for arg; do
if [[ $arg == "$term" ]]; then
return 0
fi
done
return 1
}

join_by() {
local IFS="$1"
shift
echo "$*"
}

fix=false
if has_param '-f' "$@"; then
echo "Fix mode set to true"
fix=true
fi

# Run PHP -l on everything to ensure there's no syntax
# errors.
Expand Down Expand Up @@ -45,24 +67,53 @@ declare -a tools_list=(
'manage_modules.php'
)

vendor/bin/phpcs --standard=test/LorisCS.xml --extensions=php,inc \
php/ \
htdocs/ \
modules/ \
"test/integrationtests/" \
"${tools_list[@]/#/tools/}" \
|| exit $?;
declare -a params=(
'--standard=test/LorisCS.xml'
'--extensions=php,inc'
'php/'
'htdocs/'
'modules/'
"test/integrationtests/"
"${tools_list[@]/#/tools/}"
)

if [ "$fix" = true ] ; then
vendor/bin/phpcbf $(join_by ' ' "${params[@]}") || exit $?;
else
vendor/bin/phpcs $(join_by ' ' "${params[@]}") || exit $?;
fi

# Ensure strict typing is used in these files
declare -a strict_libraries=(
'Database.class.inc'
'OutputWrapper.class.inc'
)

vendor/bin/phpcs --standard=test/StrictTypesCS.xml --extensions=php,inc "${strict_libraries[@]/#/php/libraries/}" || exit $?;
declare -a params=(
'--standard=test/StrictTypesCS.xml'
'--extensions=php,inc'
"${strict_libraries[@]/#/php/libraries/}"
)

if [ "$fix" = true ] ; then
vendor/bin/phpcbf $(join_by ' ' "${params[@]}") || exit $?;
else
vendor/bin/phpcs $(join_by ' ' "${params[@]}") || exit $?;
fi

# Run PHPCS on src/ directory using a different ruleset conforming to PSR2.
vendor/bin/phpcs --standard=test/SrcCS.xml --extensions=php/php src/ || exit $?;

declare -a params=(
'--standard=test/SrcCS.xml'
'--extensions=php/php'
'src/'
)

if [ "$fix" = true ] ; then
vendor/bin/phpcbf $(join_by ' ' "${params[@]}") || exit $?;
else
vendor/bin/phpcs $(join_by ' ' "${params[@]}") || exit $?;
fi

vendor/bin/phpmd php/,modules/,src/ text 'test/LorisPHPMD.xml' || exit $?;

Expand Down

0 comments on commit 66b637a

Please sign in to comment.