self_accessor.rst 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ======================
  2. Rule ``self_accessor``
  3. ======================
  4. Inside class or interface element ``self`` should be preferred to the class name
  5. itself.
  6. .. warning:: Using this rule is risky.
  7. Risky when using dynamic calls like get_called_class() or late static
  8. binding.
  9. Examples
  10. --------
  11. Example #1
  12. ~~~~~~~~~~
  13. .. code-block:: diff
  14. --- Original
  15. +++ New
  16. @@ -2,10 +2,10 @@
  17. class Sample
  18. {
  19. const BAZ = 1;
  20. - const BAR = Sample::BAZ;
  21. + const BAR = self::BAZ;
  22. public function getBar()
  23. {
  24. - return Sample::BAR;
  25. + return self::BAR;
  26. }
  27. }
  28. Rule sets
  29. ---------
  30. The rule is part of the following rule sets:
  31. @PhpCsFixer:risky
  32. Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``self_accessor`` rule.
  33. @Symfony:risky
  34. Using the `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_ rule set will enable the ``self_accessor`` rule.