Back to Php Cs Fixer

Rule ``multiline_promoted_properties``

doc/rules/function_notation/multiline_promoted_properties.rst

3.95.12.8 KB
Original Source

====================================== Rule multiline_promoted_properties

Promoted properties must be on separate lines.

Warnings

This rule is EXPERIMENTAL


Rule is not covered with backward compatibility promise and may produce unstable
or unexpected results, use it at your own risk. Rule's behaviour may be changed
at any point, including rule's name; its options' names, availability and
allowed values; its default configuration. Rule may be even removed without
prior notice. Feel free to provide feedback and help with determining final
state of the rule.

This rule is CONFIGURABLE

You can configure this rule using the following options: keep_blank_lines, minimum_number_of_parameters.

Configuration

keep_blank_lines


Whether to keep blank lines between properties.

Allowed types: ``bool``

Default value: ``false``

``minimum_number_of_parameters``

Minimum number of parameters in the constructor to fix.

Allowed types: int

Default value: 1

Examples

Example #1


*Default* configuration.

.. code-block:: diff

   --- Original
   +++ New
    <?php
    class Foo {
   -    public function __construct(private array $a, private bool $b, private int $i) {}
   +    public function __construct(
   +        private array $a,
   +        private bool $b,
   +        private int $i
   +    ) {}
    }

Example #2

With configuration: ['minimum_number_of_parameters' => 3].

.. code-block:: diff

--- Original +++ New <?php class Foo {

  • public function __construct(private array $a, private bool $b, private int $i) {}
  • public function __construct(
  •    private array $a,
    
  •    private bool $b,
    
  •    private int $i
    
  • ) {} } class Bar { public function __construct(private array $x) {} }

Example #3


With configuration: ``['minimum_number_of_parameters' => 3]``.

.. code-block:: diff

   --- Original
   +++ New
    <?php
    class Foo {
   -    public function __construct(
   -        private array $a,
   -        private bool $b,
   -    ) {}
   +    public function __construct(private array $a, private bool $b,) {}
    }

References
----------

- Fixer class: `PhpCsFixer\\Fixer\\FunctionNotation\\MultilinePromotedPropertiesFixer <./../../../src/Fixer/FunctionNotation/MultilinePromotedPropertiesFixer.php>`_
- Test class: `PhpCsFixer\\Tests\\Fixer\\FunctionNotation\\MultilinePromotedPropertiesFixerTest <./../../../tests/Fixer/FunctionNotation/MultilinePromotedPropertiesFixerTest.php>`_

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.