Generic Sniffs
ArrayIndent
Ensures that array are indented one tab stop.
DisallowLongArraySyntax
Bans the use of the PHP long array syntax.
DisallowShortArraySyntax
Bans the use of the PHP short array syntax.
DuplicateClassName
Reports errors if the same class or interface name is used in multiple files.
OpeningBraceSameLine
Checks that the opening brace of a class/interface/trait is on the same line as the class declaration.
AssignmentInCondition
Detects variable assignments being made within conditions.
This is a typical code smell and more often than not a comparison was intended.
Note: this sniff does not detect variable assignments in the conditional part of ternaries!
EmptyPHPStatement
Checks against empty PHP statements.
- Check against two semi-colons with no executable code in between.
- Check against an empty PHP open - close tag combination.
EmptyStatement
This sniff class detected empty statement.
This sniff implements the common algorithm for empty statement body detection. A body is considered as empty if it is completely empty or it only contains whitespace characters and/or comments.
stmt {
// foo
}
stmt (conditions) {
// foo
}
ForLoopShouldBeWhileLoop
Detects for-loops that can be simplified to a while-loop.
This rule is based on the PMD rule catalogue. Detects for-loops that can be simplified as a while-loop.
class Foo
{
public function bar($x)
{
for (;true;) true; // No Init or Update part, may as well be: while (true)
}
}
ForLoopWithTestFunctionCall
Detects for-loops that use a function call in the test expression.
This rule is based on the PMD rule catalogue. Detects for-loops that use a function call in the test expression.
class Foo
{
public function bar($x)
{
$a = array(1, 2, 3, 4);
for ($i = 0; $i < count($a); $i++) {
$a[$i] *= $i;
}
}
}
JumbledIncrementer
Detects incrementer jumbling in for loops.
This rule is based on the PMD rule catalogue. The jumbling incrementer sniff detects the usage of one and the same incrementer into an outer and an inner loop. Even it is intended this is confusing code.
class Foo
{
public function bar($x)
{
for ($i = 0; $i < 10; $i++)
{
for ($k = 0; $k < 20; $i++)
{
echo 'Hello';
}
}
}
}
UnconditionalIfStatement
Detects unconditional if- and elseif-statements.
This rule is based on the PMD rule catalogue. The Unconditional If Statement sniff detects statement conditions that are only set to one of the constant values true or false
class Foo
{
public function close()
{
if (true)
{
// ...
}
}
}
UnnecessaryFinalModifier
Detects unnecessary final modifiers inside of final classes.
This rule is based on the PMD rule catalogue. The Unnecessary Final Modifier sniff detects the use of the final modifier inside of a final class which is unnecessary.
final class Foo
{
public final function bar()
{
}
}
UnusedFunctionParameter
Checks for unused function parameters.
This sniff checks that all function parameters are used in the function body. One exception is made for empty function bodies or function bodies that only contain comments. This could be useful for the classes that implement an interface that defines multiple methods but the implementation only needs some of them.
UselessOverridingMethod
Detects unnecessary overridden methods that simply call their parent.
This rule is based on the PMD rule catalogue. The Useless Overriding Method sniff detects the use of methods that only call their parent class's method with the same name and arguments. These methods are not required.
class FooBar {
public function __construct($a, $b) {
parent::__construct($a, $b);
}
}
DocComment
Ensures doc blocks follow basic formatting.
Fixme
Warns about FIXME comments.
Todo
Warns about TODO comments.
DisallowYodaConditions
Ban the use of Yoda conditions.
InlineControlStructure
Verifies that inline control statements are not present.
ClosureLinter
Runs gjslint on the file.
CSSLint
Runs csslint on the file.
ESLint
Runs eslint on the file.
JSHint
Runs jshint.js on the file.
ByteOrderMark
A simple sniff for detecting a BOM definition that may corrupt application work.
EndFileNewline
Ensures the file ends with a newline character.
EndFileNoNewline
Ensures the file does not end with a newline character.
ExecutableFile
Tests that files are not executable.
InlineHTML
Ensures the whole file is PHP only, with no whitespace or inline HTML.
LineEndings
Checks that end of line characters are correct.
LineLength
Checks the length of all lines in a file.
Checks all lines in the file, and throws warnings if they are over 80 characters in length and errors if they are over 100. Both these figures can be changed in a ruleset.xml file.
LowercasedFilename
Checks that all file names are lowercased.
OneClassPerFile
Checks that only one class is declared per file.
OneInterfacePerFile
Checks that only one interface is declared per file.
OneObjectStructurePerFile
Checks that only one object structure is declared per file.
OneTraitPerFile
Checks that only one trait is declared per file.
DisallowMultipleStatements
Ensures each statement is on a line by itself.
MultipleStatementAlignment
Checks alignment of assignments.
If there are multiple adjacent assignments, it will check that the equals signs of each assignment are aligned. It will display a warning to advise that the signs should be aligned.
NoSpaceAfterCast
Ensures there is no space after cast tokens.
SpaceAfterCast
Ensures there is a single space after cast tokens.
SpaceAfterNot
Ensures there is a single space after a NOT operator.
SpaceBeforeCast
Ensures there is a single space before cast tokens.
CallTimePassByReference
Ensures that variables are not passed by reference when calling a function.
FunctionCallArgumentSpacing
Checks that calls to methods and functions are spaced correctly.
OpeningFunctionBraceBsdAllman
Checks that the opening brace of a function is on the line after the function declaration.
OpeningFunctionBraceKernighanRitchie
Checks that the opening brace of a function is on the same line as the function declaration.
CyclomaticComplexity
Checks the cyclomatic complexity (McCabe) for functions.
The cyclomatic complexity (also called McCabe code metrics) indicates the complexity within a function by counting the different paths the function includes.
NestingLevel
Checks the nesting level for methods.
AbstractClassNamePrefix
Checks that abstract classes are prefixed by Abstract.
CamelCapsFunctionName
Ensures method and functions are named correctly.
ConstructorName
Bans PHP 4 style constructors.
Favour PHP 5 constructor syntax, which uses "function __construct()". Avoid PHP 4 constructor syntax, which uses "function ClassName()".
InterfaceNameSuffix
Checks that interfaces are suffixed by Interface.
TraitNameSuffix
Checks that traits are suffixed by Trait.
UpperCaseConstantName
Ensures that constant names are all uppercase.
BacktickOperator
Bans the use of the backtick execution operator.
CharacterBeforePHPOpeningTag
Checks that the opening PHP tag is the first content in a file.
ClosingPHPTag
Checks that open PHP tags are paired with closing tags.
DeprecatedFunctions
Discourages the use of deprecated PHP functions.
DisallowAlternativePHPTags
Verifies that no alternative PHP tags are used.
If alternative PHP open tags are found, this sniff can fix both the open and close tags.
DisallowRequestSuperglobal
Ensures the $_REQUEST superglobal is not used
DisallowShortOpenTag
Makes sure that shorthand PHP open tags are not used.
DiscourageGoto
Discourage the use of the PHP goto
language construct.
ForbiddenFunctions
Discourages the use of alias functions.
Alias functions are kept in PHP for compatibility with older versions. Can be used to forbid the use of any function.
LowerCaseConstant
Checks that all uses of true, false and null are lowercase.
LowerCaseKeyword
Checks that all PHP keywords are lowercase.
LowerCaseType
Checks that all PHP types are lowercase.
NoSilencedErrors
Throws an error or warning when any code prefixed with an asperand is encountered.
if (@in_array($array, $needle))
{
doSomething();
}
RequireStrictTypes
Checks that the strict_types has been declared.
SAPIUsage
Ensures the PHP_SAPI constant is used instead of php_sapi_name().
Syntax
Ensures PHP believes the syntax is clean.
UpperCaseConstant
Checks that all uses of TRUE, FALSE and NULL are uppercase.
UnnecessaryStringConcat
Checks that two strings are not concatenated together; suggests using one string instead.
GitMergeConflict
Check for merge conflict artefacts.
SubversionProperties
Tests that the correct Subversion properties are set.
ArbitraryParenthesesSpacing
Check & fix whitespace on the inside of arbitrary parentheses.
Arbitrary parentheses are those which are not owned by a function (call), array or control structure. Spacing on the outside is not checked on purpose as this would too easily conflict with other spacing rules.
DisallowSpaceIndent
Throws errors if spaces are used for indentation other than precision indentation.
DisallowTabIndent
Throws errors if tabs are used for indentation.
IncrementDecrementSpacing
Verifies spacing between variables and increment/decrement operators.
LanguageConstructSpacing
Ensures all language constructs contain a single space between themselves and their content.
ScopeIndent
Checks that control structures are defined and indented correctly.
SpreadOperatorSpacingAfter
Verifies spacing between the spread operator and the variable/function call it applies to.