class_keyword.rst 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ======================
  2. Rule ``class_keyword``
  3. ======================
  4. Converts FQCN strings to ``*::class`` keywords.
  5. Description
  6. -----------
  7. This rule does not have an understanding of whether a class exists in the scope
  8. of the codebase or not, relying on run-time and autoloaded classes to determine
  9. it, which makes the rule useless when running on a single file out of codebase
  10. context.
  11. Warning
  12. -------
  13. This rule is experimental
  14. ~~~~~~~~~~~~~~~~~~~~~~~~~
  15. Rule is not covered with backward compatibility promise, use it at your own
  16. risk. Rule's behaviour may be changed at any point, including rule's name; its
  17. options' names, availability and allowed values; its default configuration. Rule
  18. may be even removed without prior notice. Feel free to provide feedback and help
  19. with determining final state of the rule.
  20. Using this rule is risky
  21. ~~~~~~~~~~~~~~~~~~~~~~~~
  22. Do not use it, unless you know what you are doing.
  23. Examples
  24. --------
  25. Example #1
  26. ~~~~~~~~~~
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. -$foo = 'PhpCsFixer\Tokenizer\Tokens';
  32. -$bar = "\PhpCsFixer\Tokenizer\Tokens";
  33. +$foo = \PhpCsFixer\Tokenizer\Tokens::class;
  34. +$bar = \PhpCsFixer\Tokenizer\Tokens::class;
  35. References
  36. ----------
  37. - Fixer class: `PhpCsFixer\\Fixer\\LanguageConstruct\\ClassKeywordFixer <./../../../src/Fixer/LanguageConstruct/ClassKeywordFixer.php>`_
  38. - Test class: `PhpCsFixer\\Tests\\Fixer\\LanguageConstruct\\ClassKeywordFixerTest <./../../../tests/Fixer/LanguageConstruct/ClassKeywordFixerTest.php>`_
  39. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.