ordered_interfaces.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ===========================
  2. Rule ``ordered_interfaces``
  3. ===========================
  4. Orders the interfaces in an ``implements`` or ``interface extends`` clause.
  5. .. warning:: Using this rule is risky.
  6. Risky for ``implements`` when specifying both an interface and its parent
  7. interface, because PHP doesn't break on ``parent, child`` but does on
  8. ``child, parent``.
  9. Configuration
  10. -------------
  11. ``order``
  12. ~~~~~~~~~
  13. How the interfaces should be ordered
  14. Allowed values: ``'alpha'``, ``'length'``
  15. Default value: ``'alpha'``
  16. ``direction``
  17. ~~~~~~~~~~~~~
  18. Which direction the interfaces should be ordered
  19. Allowed values: ``'ascend'``, ``'descend'``
  20. Default value: ``'ascend'``
  21. Examples
  22. --------
  23. Example #1
  24. ~~~~~~~~~~
  25. *Default* configuration.
  26. .. code-block:: diff
  27. --- Original
  28. +++ New
  29. <?php
  30. -final class ExampleA implements Gamma, Alpha, Beta {}
  31. +final class ExampleA implements Alpha, Beta, Gamma {}
  32. -interface ExampleB extends Gamma, Alpha, Beta {}
  33. +interface ExampleB extends Alpha, Beta, Gamma {}
  34. Example #2
  35. ~~~~~~~~~~
  36. With configuration: ``['direction' => 'descend']``.
  37. .. code-block:: diff
  38. --- Original
  39. +++ New
  40. <?php
  41. -final class ExampleA implements Gamma, Alpha, Beta {}
  42. +final class ExampleA implements Gamma, Beta, Alpha {}
  43. -interface ExampleB extends Gamma, Alpha, Beta {}
  44. +interface ExampleB extends Gamma, Beta, Alpha {}
  45. Example #3
  46. ~~~~~~~~~~
  47. With configuration: ``['order' => 'length']``.
  48. .. code-block:: diff
  49. --- Original
  50. +++ New
  51. <?php
  52. -final class ExampleA implements MuchLonger, Short, Longer {}
  53. +final class ExampleA implements Short, Longer, MuchLonger {}
  54. -interface ExampleB extends MuchLonger, Short, Longer {}
  55. +interface ExampleB extends Short, Longer, MuchLonger {}
  56. Example #4
  57. ~~~~~~~~~~
  58. With configuration: ``['order' => 'length', 'direction' => 'descend']``.
  59. .. code-block:: diff
  60. --- Original
  61. +++ New
  62. <?php
  63. -final class ExampleA implements MuchLonger, Short, Longer {}
  64. +final class ExampleA implements MuchLonger, Longer, Short {}
  65. -interface ExampleB extends MuchLonger, Short, Longer {}
  66. +interface ExampleB extends MuchLonger, Longer, Short {}