Fork me on GitHub
a Sensio Labs Product

7th Gear (v3.59.3) edition

Rule class_keyword

Converts FQCN strings to *::class keywords.


This rule does not have an understanding of whether a class exists in the scope of the codebase or not, relying on run-time and autoloaded classes to determine it, which makes the rule useless when running on a single file out of codebase context.


This rule is experimental

Rule is not covered with backward compatibility promise, use it at your own risk. Rule’s behaviour may be changed at any point, including rule’s name; its options’ names, availability and allowed values; its default configuration. Rule may be even removed without prior notice. Feel free to provide feedback and help with determining final state of the rule.

Using this rule is risky

Do not use it, unless you know what you are doing.


Example #1

--- Original
+++ New

-$foo = 'PhpCsFixer\Tokenizer\Tokens';
-$bar = "\PhpCsFixer\Tokenizer\Tokens";
+$foo = \PhpCsFixer\Tokenizer\Tokens::class;
+$bar = \PhpCsFixer\Tokenizer\Tokens::class;


The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.