2026-04-27 11:43:04 +00:00
|
|
|
#!/bin/bash
|
2026-08-14 12:57:48 +00:00
|
|
|
# Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
|
|
|
|
|
|
2026-04-27 12:24:15 +00:00
|
|
|
# Wrapper to run 'PHPStan' from pre-commit hook
|
|
|
|
|
# This is very slow so not enabled by default
|
|
|
|
|
# To enable it, create a file ~/.run-phpstan
|
|
|
|
|
# To disable it, remove this file ~/.run-phpstan
|
|
|
|
|
|
|
|
|
|
echo "Running PHPStan on files ~/vendor/bin/phpstan --level=9 -v analyze -a dev/build/phpstan/bootstrap.php $@"
|
2026-04-27 11:43:04 +00:00
|
|
|
|
|
|
|
|
# Test presence of file
|
2026-04-27 12:24:15 +00:00
|
|
|
if [ ! -f ~/.run-phpstan ]; then
|
|
|
|
|
echo "Skipping PHPStan (file ~/.run-phpstan missing)"
|
2026-04-27 11:43:04 +00:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-04-27 12:24:15 +00:00
|
|
|
if [ ! -f ~/vendor/bin/phpstan ]; then
|
2026-04-27 11:43:04 +00:00
|
|
|
echo "Skipping PHPStan (file ~/vendor/bin/phpstan missing)"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-08-14 12:57:48 +00:00
|
|
|
# phpstan.neon.dist only analyzes htdocs/ and scripts/: keep only files under these dirs so a commit
|
|
|
|
|
# that touches only out-of-scope files (test/phpunit/, dev/, doc/, ...) does not make phpstan error
|
|
|
|
|
# out with "No files found to analyse".
|
|
|
|
|
filtered=()
|
|
|
|
|
for f in "$@"; do
|
|
|
|
|
case "$f" in
|
|
|
|
|
htdocs/*|scripts/*) filtered+=("$f") ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ ${#filtered[@]} -eq 0 ]; then
|
|
|
|
|
echo "Skipping PHPStan (no file in scope: htdocs/ or scripts/)"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
~/vendor/bin/phpstan --level=9 -v analyze -a dev/build/phpstan/bootstrap.php "${filtered[@]}"
|
2026-04-27 11:43:04 +00:00
|
|
|
|
2026-04-27 12:24:15 +00:00
|
|
|
exit $?
|