single_class_element_per_statement.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  50. ``['elements' => ['property']]``
  51. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  52. ``['elements' => ['property']]``
  53. - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
  54. ``['elements' => ['property']]``
  55. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  56. ``['elements' => ['property']]``
  57. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  58. - `@Symfony <./../../ruleSets/Symfony.rst>`_