visibility_required.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ============================
  2. Rule ``visibility_required``
  3. ============================
  4. Visibility MUST be declared on all properties and methods; ``abstract`` and
  5. ``final`` MUST be declared before the visibility; ``static`` MUST be declared
  6. after the visibility.
  7. Configuration
  8. -------------
  9. ``elements``
  10. ~~~~~~~~~~~~
  11. The structural elements to fix (PHP >= 7.1 required for ``const``).
  12. Allowed values: a subset of ``['property', 'method', 'const']``
  13. Default value: ``['property', 'method']``
  14. Examples
  15. --------
  16. Example #1
  17. ~~~~~~~~~~
  18. *Default* configuration.
  19. .. code-block:: diff
  20. --- Original
  21. +++ New
  22. @@ -1,10 +1,10 @@
  23. <?php
  24. class Sample
  25. {
  26. - var $a;
  27. - static protected $var_foo2;
  28. + public $a;
  29. + protected static $var_foo2;
  30. - function A()
  31. + public function A()
  32. {
  33. }
  34. }
  35. Example #2
  36. ~~~~~~~~~~
  37. With configuration: ``['elements' => ['const']]``.
  38. .. code-block:: diff
  39. --- Original
  40. +++ New
  41. @@ -1,5 +1,5 @@
  42. <?php
  43. class Sample
  44. {
  45. - const SAMPLE = 1;
  46. + public const SAMPLE = 1;
  47. }
  48. Rule sets
  49. ---------
  50. The rule is part of the following rule sets:
  51. @PSR2
  52. Using the ``@PSR2`` rule set will enable the ``visibility_required`` rule with the default config.
  53. @Symfony
  54. Using the ``@Symfony`` rule set will enable the ``visibility_required`` rule with the default config.
  55. @PhpCsFixer
  56. Using the ``@PhpCsFixer`` rule set will enable the ``visibility_required`` rule with the default config.
  57. @PHP71Migration
  58. Using the ``@PHP71Migration`` rule set will enable the ``visibility_required`` rule with the config below:
  59. ``['elements' => ['const', 'method', 'property']]``
  60. @PHP73Migration
  61. Using the ``@PHP73Migration`` rule set will enable the ``visibility_required`` rule with the config below:
  62. ``['elements' => ['const', 'method', 'property']]``
  63. @PHP80Migration
  64. Using the ``@PHP80Migration`` rule set will enable the ``visibility_required`` rule with the config below:
  65. ``['elements' => ['const', 'method', 'property']]``