{
    "href": "/post/2023/08/14/introducing-php-styler/",
    "relId": "2023/08/14/introducing-php-styler",
    "title": "Introducing PHP-Styler",
    "author": "pmjones",
    "tags": [
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/styler/",
            "relId": "styler",
            "title": "Styler",
            "author": null,
            "created": "2023-08-14 14:20:33 UTC",
            "updated": [
                "2023-08-14 14:20:33 UTC"
            ],
            "markup": "markdown"
        }
    ],
    "created": "2023-08-14 14:20:33 UTC",
    "updated": [
        "2023-08-14 14:20:33 UTC",
        "2023-08-14 16:01:46 UTC"
    ],
    "markup": "markdown",
    "html": "<p><a href=\"https://github.com/pmjones/php-styler\">PHP-Styler</a> is a companion to <a href=\"https://github.com/nikic/PHP-Parser\">PHP-Parser</a> for reconstructing PHP code after it has been deconstructed into an abstract syntax tree. As an alternative to the pretty-printer bundled with PHP-Parser, it supports:</p>\n<ul>\n<li>configurable line-length, line-ending, and indent-string</li>\n<li>automatic indenting and line breaks</li>\n<li>automatic splitting of \"too-long\" lines</li>\n<li>programmable/customizable styling</li>\n</ul>\n<p>PHP-Styler is not a coding style \"fixer\" per se. Instead, it will completely rebuild PHP code from the AST, applying its style rules along the way. The result is a consistent formatting style, regardless of the original formatting.</p>\n<p>Whereas something like PHP-CS-Fixer has scores of configuration parameters, PHP-Styler gives you imperative control over its output. Extend the default <em>Styler</em> implementation with your own overrides to change where braces go, to place or remove the space after <code>!</code> conditions, whether or not if/elseif/else should be on separate lines, and so on.</p>\n<p>I'm especially happy with the line-splitting logic. PHP-Styler begins by building one statement per line, but if the line is too long, it follows an incremental set of rules to split that line into shorter readable parts.</p>\n<p>There are still some outstanding formatting issues around closures and comments, but I have smoke-tested PHP-Styler against several codebases besides my own, and I found the results surprisingly acceptable (not perfect, but unexpectedly good). It's certainly good enough for my own projects, though it did reveal some of my own preferences that I was not aware of, as well as some inconsistencies in my own style choices.</p>\n<p>If you are using PHP-Parser and want a better pretty-printer, or if you have been looking for an alternative to PHP-CS-Fixer, give <a href=\"https://github.com/pmjones/php-styler\">PHP-Styler</a> a try!</p>\n"
}
