php -l and lint-php.sh

Install

Nothing to install. php -l ships with every PHP interpreter. The wrapper scripts/lint-php.sh needs only the project Docker image, exactly like the other linters:

php -l src/ru/code/php/array.php ./scripts/lint-php.sh --help

Simple example

Lint one file after editing it:

php -l src/ru/.php/Rblock.php

No syntax errors detected in src/ru/.php/Rblock.php

Whole-tree syntax check from container/:

./scripts/lint-php.sh

Complex usage

Same selection flags as lint-static.sh: explicit paths, staged changes, or the whole tree. Read-only runs never modify code:

./scripts/lint-php.sh --files src/ru/.php/Rblock.php src/ru/code/php/linters/ ./scripts/lint-php.sh --staged ./scripts/lint-php.sh --all

php -l is also the safety gate of wrap-long-lines.sh --fix: every file the wrapper touches must pass php -l afterwards, otherwise the file is restored byte-for-byte and reported as failed.

What it fixed in src/

Strictly speaking php -l fixes nothing — it only reports. But it certified the two mass cleanups below:

  1. After the PHPCBF safe-sniff pass (1050 errors in 113 files) and the FileHeader pass (1735 errors in 1734 files): linted: 5105, failures: 0.
  2. After renaming 7 snake_case methods in src/ru/.php/Rblock.php (show_rblock to showRblock and friends) plus 12 callers: no syntax errors in any touched file.

php -l prints Deprecated notices it does not fail on, for example optional parameters declared before required ones in Rblock.php and Page.php. Those are left alone: fixing them is a refactor, not a syntax fix.

Автор статьи: Андрей Олегович