visibility_required.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 ``['const', 'method', 'property']``
  13. Default value: ``['property', 'method', 'const']``
  14. Examples
  15. --------
  16. Example #1
  17. ~~~~~~~~~~
  18. *Default* configuration.
  19. .. code-block:: diff
  20. --- Original
  21. +++ New
  22. <?php
  23. class Sample
  24. {
  25. - var $a;
  26. - static protected $var_foo2;
  27. + public $a;
  28. + protected static $var_foo2;
  29. - function A()
  30. + public function A()
  31. {
  32. }
  33. }
  34. Example #2
  35. ~~~~~~~~~~
  36. With configuration: ``['elements' => ['const']]``.
  37. .. code-block:: diff
  38. --- Original
  39. +++ New
  40. <?php
  41. class Sample
  42. {
  43. - const SAMPLE = 1;
  44. + public const SAMPLE = 1;
  45. }
  46. Rule sets
  47. ---------
  48. The rule is part of the following rule sets:
  49. - `@PER <./../../ruleSets/PER.rst>`_
  50. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  51. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  52. - `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_
  53. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_
  54. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_
  55. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_
  56. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_
  57. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_
  58. - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
  59. ``['elements' => ['method', 'property']]``
  60. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  61. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  62. - `@Symfony <./../../ruleSets/Symfony.rst>`_