MediaWiki-CodeSniffer
MediaWiki CodeSniffer Standards
Loading...
Searching...
No Matches
MediaWiki\Sniffs\Classes\FullQualifiedClassNameSniff Class Reference

Custom sniff that disallows full qualified class names outside of the "use …" section. More...

+ Inheritance diagram for MediaWiki\Sniffs\Classes\FullQualifiedClassNameSniff:

Public Member Functions

 register ()
 @inheritDoc
 
 process (File $phpcsFile, $stackPtr)
 @inheritDoc
 

Public Attributes

bool $allowMainNamespace = true
 
bool $allowInheritance = true
 
bool $allowFunctions = true
 

Detailed Description

Custom sniff that disallows full qualified class names outside of the "use …" section.

Exceptions:

  • Full qualified class names in the main namespace (e.g. \Title) are allowed, by default. This is a very common code style in MediaWiki-related codebases. Removing these backslash characters doesn't really make code better readable.
  • Full qualified class names in "extends" and "implements" are allowed, by default. This is a very common code style, especially in tests. Since these can only appear once per class, and are guaranteed to be at the very top, moving them to "use" statements doesn't really make code better readable.
  • Function calls like \Wikimedia\suppressWarnings() are allowed, by default.

Note this sniff is disabled by default. You need to increase it's severity in your .phpcs.xml to enable it.

Example configuration: <rule ref="MediaWiki.Classes.FullQualifiedClassName"> <severity>5</severity> <properties> <property name="allowMainNamespace" value="false" > <property name="allowInheritance" value="false" > <property name="allowFunctions" value="false" > </properties> </rule>

Note this sniff currently does not check class names mentioned in PHPDoc comments.

Author
Thiemo Kreuz

The documentation for this class was generated from the following file: