wrap-long-lines.sh
| Install | |
| Simple example | |
| Complex usage | |
| What it fixed in src/ |
Install
Nothing to install: scripts/wrap-long-lines.sh is bash plus embedded Python 3, no extra packages. All commands run from container/. --fix needs a PHP binary for its post-fix syntax gate (running stack via docker exec php-apache php, else host php or --php-bin); without one it refuses to modify files. --validate needs the PHPCS phar, fetched once via lint-static.sh --tool phpcs:
./scripts/wrap-long-lines.sh --help ./scripts/lint-static.sh --tool phpcs --files src/dev/php/linters/wrap_long_lines.php
Simple example
List every line over 120 characters (read-only, exit 1 on findings):
./scripts/wrap-long-lines.sh --search src/ru/qa/tasks/plan.php
src/ru/qa/tasks/plan.php:20:409: $ads_block = ...
Wrap them in place:
./scripts/wrap-long-lines.sh --fix src/dev/python/issues/RelatedArticles.php
Complex usage
Custom limit, explicit PHP binary, and proving zero PHPCS regressions:
./scripts/wrap-long-lines.sh --fix --limit 100 --php-bin "docker exec php-apache php" src/qa/ ./scripts/wrap-long-lines.sh --fix --validate src/dev/python/issues/RelatedArticles.php ./scripts/wrap-long-lines.sh --search src/ | tee long-lines.txt
Split points, in order: top-level commas (one argument per line), . concatenation (operator starts the continuation line), = / =>. Only lines fully inside <?php ... ?> are touched; HTML and template text is reported as ignored, never penalized.
What it fixed in src/
The 409-character line 20 of src/ru/qa/tasks/plan.php cannot be wrapped by the tool — the whole right-hand side is one single-quoted string, and the script never splits inside string literals:
$ads_block = '<div class="p5 ...>...</div>';
UNCHANGED src/ru/qa/tasks/plan.php skipped=1 ignored=0
Splitting after = alone would still leave a 400-character string line, so the tool reports skipped instead of inventing new . operators. Fixed by hand with concatenation:
$ads_block = '<div ...><script ...></script>'
. '<!-- ao_python_vert --><ins ...></ins>'
. '<script>...</script></div>';
Rule of thumb: if --search flags a line and --fix skips it, split the string literal yourself — then re-run with --validate.
Article author: Andrei Olegovich
| Development with PHP | |
| PHP linters we use | |
| php -l and lint-php.sh | |
| PHPCS: PHP CodeSniffer | |
| phpcs.xml ruleset file | |
| PHPCBF: fix style automatically | |
| wrap-long-lines.sh | |
| PHPStan and Psalm |