Files
main/tools/php_syntax_check.sh
Divarion-D d8717d2499 ci: extract PHP syntax check into reusable script
- Add tools/php_syntax_check.sh (supports full scan + single-file mode)
- CI workflow now calls the shared script
- All 6 agents updated to reference the script
- CONTRIBUTING.md: add Pre-Commit Checks section
- Exclude src/bin/* (third-party stubs) from lint
2026-03-15 13:49:18 +03:00

35 lines
983 B
Bash

#!/bin/bash
set -euo pipefail
# PHP syntax checker for the XC_VM project.
# Scans all .php files under src/, excluding src/bin/* (third-party stubs).
# Exit code: 0 if no errors, 1 if any file has syntax errors.
#
# Usage:
# ./tools/php_syntax_check.sh # check all src/*.php
# ./tools/php_syntax_check.sh src/domain/Device/EnigmaService.php # check one file
ERRORS=0
CHECKED=0
if [[ $# -gt 0 ]]; then
for file in "$@"; do
if ! php -l "$file" 2>&1 | grep -q "No syntax errors"; then
php -l "$file"
ERRORS=$((ERRORS + 1))
fi
CHECKED=$((CHECKED + 1))
done
else
while IFS= read -r -d '' file; do
if ! php -l "$file" 2>&1 | grep -q "No syntax errors"; then
php -l "$file"
ERRORS=$((ERRORS + 1))
fi
CHECKED=$((CHECKED + 1))
done < <(find src -name '*.php' -not -path 'src/bin/*' -print0)
fi
echo "Checked $CHECKED files, $ERRORS errors"
[[ "$ERRORS" -eq 0 ]]