visibility_required.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-CS <./../../ruleSets/PER-CS.rst>`_
  51. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  52. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  53. - `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_
  54. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_
  55. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_
  56. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_
  57. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_
  58. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_
  59. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_
  60. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_
  61. - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
  62. ``['elements' => ['method', 'property']]``
  63. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  64. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  65. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  66. References
  67. ----------
  68. - Fixer class: `PhpCsFixer\\Fixer\\ClassNotation\\VisibilityRequiredFixer <./../../../src/Fixer/ClassNotation/VisibilityRequiredFixer.php>`_
  69. - Test class: `PhpCsFixer\\Tests\\Fixer\\ClassNotation\\VisibilityRequiredFixerTest <./../../../tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php>`_
  70. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.