suhock/php-cs-fixer-rules

A set of custom PHP CS Fixer rules

Maintainers

Package info

github.com/suhock/php-cs-fixer-rules

pkg:composer/suhock/php-cs-fixer-rules

Transparency log

Statistics

Installs: 4

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-07-24 08:04 UTC

This package is auto-updated.

Last update: 2026-07-24 08:23:08 UTC


README

A set of custom PHP CS Fixer rules.

Contents

Installation

composer require --dev suhock/php-cs-fixer-rules

Register the fixers in your .php-cs-fixer.dist.php:

return (new PhpCsFixer\Config())
    ->registerCustomFixers(new Suhock\PhpCsFixer\Fixers())
    ->setRules([
        // ... your other rules ...
        'Suhock/method_chain_splitting' => true,
        'Suhock/phpdoc_tag_hanging_indent' => true,
    ])
    ->setFinder(/* ... */);

Rules

Suhock/method_chain_splitting

Breaks a method-call chain across multiple lines, putting each -> / ?-> call on its own line indented one level past the object it is called on.

// before
$this->foo()->bar()->baz();

// after
$this
    ->foo()
    ->bar()
    ->baz();

A chain that already spans more than one line is always normalized to this layout.

This fixer provides only nominal indentation to the wrapped calls. It runs before method_chaining_indentation and statement_indentation, so those fixers can reconcile the indentation of any call arguments that themselves span multiple lines. Pair it with method_chaining_indentation for chains with multi-line arguments.

Configuration

Option Type Default Description
calls_on_first_line int 0 Number of calls to keep or pull onto the first line, breaking only before the calls that follow; 0 breaks every call
max_calls_in_single_line_chain int 1 Maximum number of calls a single-line chain may contain before it is broken
calls_on_first_line
'Suhock/method_chain_splitting' => ['calls_on_first_line' => 1],
$this->foo()
    ->bar();

If the chain is already broken into multiple lines, the specified number of calls will be pulled back up to the first line.

// before
$this
    ->foo()
    ->bar();

// after
$this->foo()
    ->bar();
max_calls_in_single_line_chain
'Suhock/method_chain_splitting' => ['max_calls_in_single_line_chain' => 2],
// Left untouched as a single line chain
$this->foo()->bar();
// Before
$this->foo()->bar()->baz();

// After
$this
    ->foo()
    ->bar()
    ->baz();
// Left untouched. Already multi-line so never pulled back into single line.
$this
    ->foo()
    ->bar();

Suhock/phpdoc_tag_hanging_indent

Indents the wrapped continuation lines of a PHPDoc tag description by a fixed hanging indent, so a multi-line @param / @return / @throws / etc. description reads as one block. The docblock summary and long-description prose are left untouched.

// before
/**
 * @param string $name Lorem ipsum dolor sit amet
 * consectetur adipiscing elit quisque.
 */

// after
/**
 * @param string $name Lorem ipsum dolor sit amet
 *     consectetur adipiscing elit quisque.
 */

Configuration

Option Type Default Description
indent int 4 Number of spaces to indent a wrapped line past the first line of the description
'Suhock/phpdoc_tag_hanging_indent' => ['indent' => 2],

This fixer runs after phpdoc_align, so it has the final say on continuation indentation.

Fills the gap tracked upstream in PHP-CS-Fixer#4692: phpdoc_align aligns tag columns but provides no control over wrapped-line indentation.