wrap-long-lines.sh

Contents
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

Related articles
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
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: