single_class_element_per_statement.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ===========================================
  2. Rule ``single_class_element_per_statement``
  3. ===========================================
  4. There MUST NOT be more than one property or constant declared per statement.
  5. Configuration
  6. -------------
  7. ``elements``
  8. ~~~~~~~~~~~~
  9. List of strings which element should be modified.
  10. Allowed values: a subset of ``['const', 'property']``
  11. Default value: ``['const', 'property']``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. final class Example
  22. {
  23. - const FOO_1 = 1, FOO_2 = 2;
  24. - private static $bar1 = array(1,2,3), $bar2 = [1,2,3];
  25. + const FOO_1 = 1;
  26. + const FOO_2 = 2;
  27. + private static $bar1 = array(1,2,3);
  28. + private static $bar2 = [1,2,3];
  29. }
  30. Example #2
  31. ~~~~~~~~~~
  32. With configuration: ``['elements' => ['property']]``.
  33. .. code-block:: diff
  34. --- Original
  35. +++ New
  36. <?php
  37. final class Example
  38. {
  39. const FOO_1 = 1, FOO_2 = 2;
  40. - private static $bar1 = array(1,2,3), $bar2 = [1,2,3];
  41. + private static $bar1 = array(1,2,3);
  42. + private static $bar2 = [1,2,3];
  43. }
  44. Rule sets
  45. ---------
  46. The rule is part of the following rule sets:
  47. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  48. ``['elements' => ['property']]``
  49. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  50. ``['elements' => ['property']]``
  51. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  52. ``['elements' => ['property']]``
  53. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  54. ``['elements' => ['property']]``
  55. - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
  56. ``['elements' => ['property']]``
  57. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  58. ``['elements' => ['property']]``
  59. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  60. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  61. References
  62. ----------
  63. - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\SingleClassElementPerStatementFixer <./../../../src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php>`_
  64. - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\SingleClassElementPerStatementFixerTest <./../../../tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php>`_
  65. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.