class_definition.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. =========================
  2. Rule ``class_definition``
  3. =========================
  4. Whitespace around the keywords of a class, trait or interfaces definition should
  5. be one space.
  6. Configuration
  7. -------------
  8. ``multi_line_extends_each_single_line``
  9. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. Whether definitions should be multiline.
  11. .. note:: The previous name of this option was ``multiLineExtendsEachSingleLine`` but it is now deprecated and will be removed on next major version.
  12. Allowed types: ``bool``
  13. Default value: ``false``
  14. ``single_item_single_line``
  15. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. Whether definitions should be single line when including a single item.
  17. .. note:: The previous name of this option was ``singleItemSingleLine`` but it is now deprecated and will be removed on next major version.
  18. Allowed types: ``bool``
  19. Default value: ``false``
  20. ``single_line``
  21. ~~~~~~~~~~~~~~~
  22. Whether definitions should be single line.
  23. .. note:: The previous name of this option was ``singleLine`` but it is now deprecated and will be removed on next major version.
  24. Allowed types: ``bool``
  25. Default value: ``false``
  26. Examples
  27. --------
  28. Example #1
  29. ~~~~~~~~~~
  30. *Default* configuration.
  31. .. code-block:: diff
  32. --- Original
  33. +++ New
  34. @@ -1,13 +1,13 @@
  35. <?php
  36. -class Foo extends Bar implements Baz, BarBaz
  37. +class Foo extends Bar implements Baz, BarBaz
  38. {
  39. }
  40. -final class Foo extends Bar implements Baz, BarBaz
  41. +final class Foo extends Bar implements Baz, BarBaz
  42. {
  43. }
  44. -trait Foo
  45. +trait Foo
  46. {
  47. }
  48. Example #2
  49. ~~~~~~~~~~
  50. *Default* configuration.
  51. .. code-block:: diff
  52. --- Original
  53. +++ New
  54. @@ -1,3 +1,3 @@
  55. <?php
  56. -$foo = new class extends Bar implements Baz, BarBaz {};
  57. +$foo = new class extends Bar implements Baz, BarBaz {};
  58. Example #3
  59. ~~~~~~~~~~
  60. With configuration: ``['single_line' => true]``.
  61. .. code-block:: diff
  62. --- Original
  63. +++ New
  64. @@ -1,6 +1,4 @@
  65. <?php
  66. -class Foo
  67. -extends Bar
  68. -implements Baz, BarBaz
  69. +class Foo extends Bar implements Baz, BarBaz
  70. {}
  71. Example #4
  72. ~~~~~~~~~~
  73. With configuration: ``['single_item_single_line' => true]``.
  74. .. code-block:: diff
  75. --- Original
  76. +++ New
  77. @@ -1,6 +1,4 @@
  78. <?php
  79. -class Foo
  80. -extends Bar
  81. -implements Baz
  82. +class Foo extends Bar implements Baz
  83. {}
  84. Example #5
  85. ~~~~~~~~~~
  86. With configuration: ``['multi_line_extends_each_single_line' => true]``.
  87. .. code-block:: diff
  88. --- Original
  89. +++ New
  90. @@ -1,5 +1,7 @@
  91. <?php
  92. interface Bar extends
  93. - Bar, BarBaz, FooBarBaz
  94. + Bar,
  95. + BarBaz,
  96. + FooBarBaz
  97. {}
  98. Rule sets
  99. ---------
  100. The rule is part of the following rule sets:
  101. @PSR2
  102. Using the ``@PSR2`` rule set will enable the ``class_definition`` rule with the default config.
  103. @Symfony
  104. Using the ``@Symfony`` rule set will enable the ``class_definition`` rule with the config below:
  105. ``['single_line' => true]``
  106. @PhpCsFixer
  107. Using the ``@PhpCsFixer`` rule set will enable the ``class_definition`` rule with the config below:
  108. ``['single_line' => true]``