123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- ====================================
- Rule ``class_attributes_separation``
- ====================================
- Class, trait and interface elements must be separated with one or none blank
- line.
- Configuration
- -------------
- ``elements``
- ~~~~~~~~~~~~
- Dictionary of ``const|method|property|trait_import|case`` =>
- ``none|one|only_if_meta`` values.
- Allowed types: ``array<string, string>``
- Default value: ``['const' => 'one', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none', 'case' => 'none']``
- Examples
- --------
- Example #1
- ~~~~~~~~~~
- *Default* configuration.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- final class Sample
- {
- protected function foo()
- {
- }
- +
- protected function bar()
- {
- }
- -
- -
- }
- Example #2
- ~~~~~~~~~~
- With configuration: ``['elements' => ['property' => 'one']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- class Sample
- -{private $a; // foo
- +{
- +private $a; // foo
- +
- /** second in a hour */
- private $b;
- }
- Example #3
- ~~~~~~~~~~
- With configuration: ``['elements' => ['const' => 'one']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- class Sample
- {
- const A = 1;
- +
- /** seconds in some hours */
- const B = 3600;
- }
- Example #4
- ~~~~~~~~~~
- With configuration: ``['elements' => ['const' => 'only_if_meta']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- class Sample
- {
- /** @var int */
- const SECOND = 1;
- +
- /** @var int */
- const MINUTE = 60;
- -
- const HOUR = 3600;
- -
- const DAY = 86400;
- }
- Example #5
- ~~~~~~~~~~
- With configuration: ``['elements' => ['property' => 'only_if_meta']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- class Sample
- {
- public $a;
- +
- #[SetUp]
- public $b;
- +
- /** @var string */
- public $c;
- +
- /** @internal */
- #[Assert\String()]
- public $d;
- -
- public $e;
- }
- Rule sets
- ---------
- The rule is part of the following rule sets:
- - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
- ``['elements' => ['method' => 'one']]``
- - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
- ``['elements' => ['method' => 'one']]``
- References
- ----------
- - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\ClassAttributesSeparationFixer <./../../../src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php>`_
- - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\ClassAttributesSeparationFixerTest <./../../../tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php>`_
- The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
|