ordered_interfaces.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ===========================
  2. Rule ``ordered_interfaces``
  3. ===========================
  4. Orders the interfaces in an ``implements`` or ``interface extends`` clause.
  5. Configuration
  6. -------------
  7. ``case_sensitive``
  8. ~~~~~~~~~~~~~~~~~~
  9. Whether the sorting should be case sensitive.
  10. Allowed types: ``bool``
  11. Default value: ``false``
  12. ``direction``
  13. ~~~~~~~~~~~~~
  14. Which direction the interfaces should be ordered.
  15. Allowed values: ``'ascend'`` and ``'descend'``
  16. Default value: ``'ascend'``
  17. ``order``
  18. ~~~~~~~~~
  19. How the interfaces should be ordered.
  20. Allowed values: ``'alpha'`` and ``'length'``
  21. Default value: ``'alpha'``
  22. Examples
  23. --------
  24. Example #1
  25. ~~~~~~~~~~
  26. *Default* configuration.
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. -final class ExampleA implements Gamma, Alpha, Beta {}
  32. +final class ExampleA implements Alpha, Beta, Gamma {}
  33. -interface ExampleB extends Gamma, Alpha, Beta {}
  34. +interface ExampleB extends Alpha, Beta, Gamma {}
  35. Example #2
  36. ~~~~~~~~~~
  37. With configuration: ``['direction' => 'descend']``.
  38. .. code-block:: diff
  39. --- Original
  40. +++ New
  41. <?php
  42. -final class ExampleA implements Gamma, Alpha, Beta {}
  43. +final class ExampleA implements Gamma, Beta, Alpha {}
  44. -interface ExampleB extends Gamma, Alpha, Beta {}
  45. +interface ExampleB extends Gamma, Beta, Alpha {}
  46. Example #3
  47. ~~~~~~~~~~
  48. With configuration: ``['order' => 'length']``.
  49. .. code-block:: diff
  50. --- Original
  51. +++ New
  52. <?php
  53. -final class ExampleA implements MuchLonger, Short, Longer {}
  54. +final class ExampleA implements Short, Longer, MuchLonger {}
  55. -interface ExampleB extends MuchLonger, Short, Longer {}
  56. +interface ExampleB extends Short, Longer, MuchLonger {}
  57. Example #4
  58. ~~~~~~~~~~
  59. With configuration: ``['order' => 'length', 'direction' => 'descend']``.
  60. .. code-block:: diff
  61. --- Original
  62. +++ New
  63. <?php
  64. -final class ExampleA implements MuchLonger, Short, Longer {}
  65. +final class ExampleA implements MuchLonger, Longer, Short {}
  66. -interface ExampleB extends MuchLonger, Short, Longer {}
  67. +interface ExampleB extends MuchLonger, Longer, Short {}
  68. Example #5
  69. ~~~~~~~~~~
  70. With configuration: ``['order' => 'alpha']``.
  71. .. code-block:: diff
  72. --- Original
  73. +++ New
  74. <?php
  75. -final class ExampleA implements IgnorecaseB, IgNoReCaSeA, IgnoreCaseC {}
  76. +final class ExampleA implements IgNoReCaSeA, IgnorecaseB, IgnoreCaseC {}
  77. -interface ExampleB extends IgnorecaseB, IgNoReCaSeA, IgnoreCaseC {}
  78. +interface ExampleB extends IgNoReCaSeA, IgnorecaseB, IgnoreCaseC {}
  79. Example #6
  80. ~~~~~~~~~~
  81. With configuration: ``['order' => 'alpha', 'case_sensitive' => true]``.
  82. .. code-block:: diff
  83. --- Original
  84. +++ New
  85. <?php
  86. -final class ExampleA implements Casesensitivea, CaseSensitiveA, CasesensitiveA {}
  87. +final class ExampleA implements CaseSensitiveA, CasesensitiveA, Casesensitivea {}
  88. -interface ExampleB extends Casesensitivea, CaseSensitiveA, CasesensitiveA {}
  89. +interface ExampleB extends CaseSensitiveA, CasesensitiveA, Casesensitivea {}
  90. References
  91. ----------
  92. - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\OrderedInterfacesFixer <./../../../src/Fixer/ClassNotation/OrderedInterfacesFixer.php>`_
  93. - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\OrderedInterfacesFixerTest <./../../../tests/Fixer/ClassNotation/OrderedInterfacesFixerTest.php>`_
  94. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.