final_internal_class.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_exclude``
  13. ~~~~~~~~~~~~~~~~~~~~~~
  14. .. warning:: This option is deprecated and will be removed in the next major version. Use ``exclude`` to configure PHPDoc annotations tags and attributes.
  15. Class level attribute or annotation tags that must be omitted to fix the class,
  16. even if all of the white list ones are used as well (case insensitive).
  17. Allowed types: ``list<string>``
  18. Default value: ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity', '@Document', '@ODM\\Document']``
  19. ``annotation_include``
  20. ~~~~~~~~~~~~~~~~~~~~~~
  21. .. warning:: This option is deprecated and will be removed in the next major version. Use ``include`` to configure PHPDoc annotations tags and attributes.
  22. Class level attribute or annotation tags that must be set in order to fix the
  23. class (case insensitive).
  24. Allowed types: ``list<string>``
  25. Default value: ``['@internal']``
  26. ``consider_absent_docblock_as_internal_class``
  27. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. Whether classes without any DocBlock should be fixed to final.
  29. Allowed types: ``bool``
  30. Default value: ``false``
  31. ``exclude``
  32. ~~~~~~~~~~~
  33. Class level attribute or annotation tags that must be omitted to fix the class,
  34. even if all of the white list ones are used as well (case insensitive).
  35. Allowed types: ``list<string>``
  36. Default value: ``['final', 'Entity', 'ORM\\Entity', 'ORM\\Mapping\\Entity', 'Mapping\\Entity', 'Document', 'ODM\\Document']``
  37. ``include``
  38. ~~~~~~~~~~~
  39. Class level attribute or annotation tags that must be set in order to fix the
  40. class (case insensitive).
  41. Allowed types: ``list<string>``
  42. Default value: ``['internal']``
  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>`_
  80. References
  81. ----------
  82. - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\FinalInternalClassFixer <./../../../src/Fixer/ClassNotation/FinalInternalClassFixer.php>`_
  83. - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\FinalInternalClassFixerTest <./../../../tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php>`_
  84. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.