no_unneeded_final_method.rst 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. =================================
  2. Rule ``no_unneeded_final_method``
  3. =================================
  4. Removes ``final`` from methods where possible.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky when child class overrides a ``private`` method.
  10. Configuration
  11. -------------
  12. ``private_methods``
  13. ~~~~~~~~~~~~~~~~~~~
  14. Private methods of non-``final`` classes must not be declared ``final``.
  15. Allowed types: ``bool``
  16. Default value: ``true``
  17. Examples
  18. --------
  19. Example #1
  20. ~~~~~~~~~~
  21. *Default* configuration.
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. <?php
  26. final class Foo
  27. {
  28. - final public function foo1() {}
  29. - final protected function bar() {}
  30. - final private function baz() {}
  31. + public function foo1() {}
  32. + protected function bar() {}
  33. + private function baz() {}
  34. }
  35. class Bar
  36. {
  37. - final private function bar1() {}
  38. + private function bar1() {}
  39. }
  40. Example #2
  41. ~~~~~~~~~~
  42. With configuration: ``['private_methods' => false]``.
  43. .. code-block:: diff
  44. --- Original
  45. +++ New
  46. <?php
  47. final class Foo
  48. {
  49. - final private function baz() {}
  50. + private function baz() {}
  51. }
  52. class Bar
  53. {
  54. final private function bar1() {}
  55. }
  56. Rule sets
  57. ---------
  58. The rule is part of the following rule sets:
  59. - `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_
  60. - `@PHP82Migration:risky <./../../ruleSets/PHP82MigrationRisky.rst>`_
  61. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  62. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_
  63. References
  64. ----------
  65. - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\NoUnneededFinalMethodFixer <./../../../src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php>`_
  66. - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\NoUnneededFinalMethodFixerTest <./../../../tests/Fixer/ClassNotation/NoUnneededFinalMethodFixerTest.php>`_
  67. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.