final_internal_class.rst 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. =============================
  2. Rule ``final_internal_class``
  3. =============================
  4. Internal classes should be ``final``.
  5. .. warning:: Using this rule is risky.
  6. Changing classes to ``final`` might cause code execution to break.
  7. Configuration
  8. -------------
  9. ``annotation_include``
  10. ~~~~~~~~~~~~~~~~~~~~~~
  11. Class level annotations tags that must be set in order to fix the class. (case
  12. insensitive)
  13. Allowed types: ``array``
  14. Default value: ``['@internal']``
  15. ``annotation_exclude``
  16. ~~~~~~~~~~~~~~~~~~~~~~
  17. Class level annotations tags that must be omitted to fix the class, even if all
  18. of the white list ones are used as well. (case insensitive)
  19. Allowed types: ``array``
  20. Default value: ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity']``
  21. ``consider_absent_docblock_as_internal_class``
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. Should classes without any DocBlock be fixed to final?
  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. @@ -2,6 +2,6 @@
  35. /**
  36. * @internal
  37. */
  38. -class Sample
  39. +final class Sample
  40. {
  41. }
  42. Example #2
  43. ~~~~~~~~~~
  44. With configuration: ``['annotation_include' => ['@Custom'], 'annotation_exclude' => ['@not-fix']]``.
  45. .. code-block:: diff
  46. --- Original
  47. +++ New
  48. @@ -2,7 +2,7 @@
  49. /**
  50. * @CUSTOM
  51. */
  52. -class A{}
  53. +final class A{}
  54. /**
  55. * @CUSTOM
  56. Rule sets
  57. ---------
  58. The rule is part of the following rule set:
  59. @PhpCsFixer:risky
  60. Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``final_internal_class`` rule with the default config.