no_unneeded_final_method.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  61. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_