final_internal_class.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. =============================
  2. Rule ``final_internal_class``
  3. =============================
  4. Internal classes should be ``final``.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Changing classes to ``final`` might cause code execution to break.
  10. Configuration
  11. -------------
  12. ``annotation_include``
  13. ~~~~~~~~~~~~~~~~~~~~~~
  14. .. warning:: This option is deprecated and will be removed on next major version. Use ``include`` to configure PHPDoc annotations tags and attributes.
  15. Class level attribute or annotation tags that must be set in order to fix the
  16. class (case insensitive).
  17. Allowed types: ``array``
  18. Default value: ``['@internal']``
  19. ``annotation_exclude``
  20. ~~~~~~~~~~~~~~~~~~~~~~
  21. .. warning:: This option is deprecated and will be removed on next major version. Use ``exclude`` to configure PHPDoc annotations tags and attributes.
  22. Class level attribute or annotation tags that must be omitted to fix the class,
  23. even if all of the white list ones are used as well (case insensitive).
  24. Allowed types: ``array``
  25. Default value: ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity', '@Document', '@ODM\\Document']``
  26. ``include``
  27. ~~~~~~~~~~~
  28. Class level attribute or annotation tags that must be set in order to fix the
  29. class (case insensitive).
  30. Allowed types: ``array``
  31. Default value: ``['internal']``
  32. ``exclude``
  33. ~~~~~~~~~~~
  34. Class level attribute or annotation tags that must be omitted to fix the class,
  35. even if all of the white list ones are used as well (case insensitive).
  36. Allowed types: ``array``
  37. Default value: ``['final', 'Entity', 'ORM\\Entity', 'ORM\\Mapping\\Entity', 'Mapping\\Entity', 'Document', 'ODM\\Document']``
  38. ``consider_absent_docblock_as_internal_class``
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. Whether classes without any DocBlock should be fixed to final.
  41. Allowed types: ``bool``
  42. Default value: ``false``
  43. Examples
  44. --------
  45. Example #1
  46. ~~~~~~~~~~
  47. *Default* configuration.
  48. .. code-block:: diff
  49. --- Original
  50. +++ New
  51. <?php
  52. /**
  53. * @internal
  54. */
  55. -class Sample
  56. +final class Sample
  57. {
  58. }
  59. Example #2
  60. ~~~~~~~~~~
  61. With configuration: ``['include' => ['@Custom'], 'exclude' => ['@not-fix']]``.
  62. .. code-block:: diff
  63. --- Original
  64. +++ New
  65. <?php
  66. /**
  67. * @CUSTOM
  68. */
  69. -class A{}
  70. +final class A{}
  71. /**
  72. * @CUSTOM
  73. * @not-fix
  74. */
  75. class B{}
  76. Rule sets
  77. ---------
  78. The rule is part of the following rule set:
  79. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_