-
Notifications
You must be signed in to change notification settings - Fork 31
Checks
The configuration file used by default is config/default.xml.
You customize this to suit it to specific coding convention by creating a new configuration file and commenting/uncommenting some tests.
For some tests, you can list some exceptions when you don't want the test to be applied.
You can also edit the level of severity of each test by adding a "level" attribute in the XML configuration file.
The list of available tests is detailled below.
Checks to see if the constant follows the naming convention. Constants should only have uppercase letters and underscores.
Checks to see if the variable follows the naming convention. Variables should start with a lowercase or an underscores and should contain only letters.
If you need to be more precise, you can differentiate between :
- topLevelVariableNaming : for top level variables
- localVariableNaming : for local variables (inside a class)
- memberVariableNaming : for member variables (inside a function)
Checks to see if the function follows the naming convention. Function name has to start with lowercase (the pattern is customizable with a regexp). Special functions (like "__construct" are not checked).
Activates the testing for protected functions.
Activates the testing for private functions (private functions should start with a underscore followed by lowercase, the pattern is customizable).
Checks the naming of the constructor, the property "naming" can be set to "old" for old PHP constructor style (the name of the class) or to "new" for the new constructor style "__construct()".
Checks to see if the class follows the naming convention (class name has to start with uppercase).
Checks to see if the interface follows the naming convention.
Checks to see if the PHP file name follows the naming convention.
Tests and reports an error if a short php code open tag is used. Anything other than "<?php" is an error.
Test if a PHP closing file is present at the end of a file (which is not recommended)
Test if a file finish with some inner HTML. This could be OK for some files likes view (in a MVC framework) but could provoque a "header already sent" error in some cases.
Check the the PHP tags are always at the beginning of a line.
Tests and reports and error if there is a shell/perl style comment (that starts with '#').
Tests that every function and class is immediately preceded by a docblock. A property "excludePrivateMembers" can be set if you want to disable docblocks for private member functions. If the docBlocks contains "@inheritdoc" then all the checks are disabled. You can also disable the check for some functions by using an exception with the name of the function.
- Property excludePrivateMembers (true / false)
- Property testReturn (true / false)
- Property testParam (true / false)
- Property testThrow (true / false)
Check for the presence of a mandatory header at the beginning of each file.
/**
* Header : Copyright notice ...
*/
Check the indentation type. If spaces are expected, checks that a line does not contain the tab character and that the number of spaces is correct. If tabs are expected, checks that the line contains no spaces.
Tests to make sure that every control structure is included within a {} block, even if it is syntactically optional.
Tests for the location of the open curly bracket for a control structure. Default position is the same line where control statement ends. It can be overridden to position it on a new line by setting the property "position" to "nl".
- Property position (sl/nl)
Example: open curly bracket on the same line:
if ($ret === false) {
// statements
}
Same example, if the open curly bracket was supposed to be on the new line:
if ($ret === false)
{
// statements
}
Checks the position of the close curly brace (Should always be on a new line).
This is similar to "controlStructOpenCurly" explained above. Except that this is for function definition and the default value of "position" is new line ("nl").
- Property position (sl/nl)
Checks the position of the else after the end of the if statement.
- Property position (sl/nl)
Same line :
if ($ret === false) {
// statements
} else {
}
New line :
if ($ret === false) {
// statements
}
else {
}
Defines the prefered style for quotes ("single" or "double").
Tests that the control statements ("if", "else", "while", "for", etc.) are followed by a space before the opening parenthesis. PEAR standard stipulates this to distinguish it from function calls.
Tests that the control statements ("if", "else", "while", "for", etc.) are NOT followed by a space before the opening parenthesis.
Check that there is no space after a function name in a function call.
heck for the (required) presence of a white space after some tokens (like ,).
- A list of exceptions can be defined for this test.
Check for the (required) presence of a white space before some tokens.
- A list of exceptions can be defined for this test.
Check that there is no space before before some tokens.
- A list of exceptions can be defined for this test.
Check that there is no space after some tokens.
- A list of exceptions can be defined for this test.
Tests for long lines (except for comments) and reports error if a line exceeds the value of "maxLineLength" property.
- Proprety maxLineLength (default = 80).
Checks that the lenght (in lines) of a function doesn't pass the max value.
- Proprety maxLength (default = 150).
Checks for excessive parameters in a function declaration.
- Proprety maxParameters(default = 4).
Calculates a simple cyclomatic complexity value for the functions. The level of complexity that raise a warning or an error can be defined. See Cyclomatic Complexity
- Proprety warningLevel (default = 10).
- Proprety errorLevel(default = 20).
Calculates the NPath complexity (see NPath complexity explained).
- Proprety warningLevel (default = 100).
- Proprety errorLevel(default = 200).
Checks for prohibited functions. List the functions that are forbidden in a project for safety reasons (like for example "exec"). See the list of PHP functions here
Checks for prohibited tokens. List the PHP tokens that are forbidden. See the list of PHP tokens here
Tests that all the arguments of a function with default values are placed at the end of the list of arguments.
Checks for silenced function calls.
- A list of exceptions can be defined for this test.
Checks for encapsed variables inside a String like "$a".
Checks for functions have some passed by reference parameters.
Extracts the TODO from the comments and add them in the report.
Tests for the presence of boolean operators (AND or OR) and recommend to replace them with boolean operators (&& or ||).
Check empty block like if ($a) {}
- A list of exceptions can be defined for this test.
Check empty statement ( ;; )
Check for the presence of heredoc.
Check for braces around code blocs (if, else, elseif, do, while, for, foreach).
Switch need a default value.
Switch case should have a break.
Switch default value should be at the end.
Avoid using unary operators (++) inside a control statement. With the exception of for iterators, all variable incrementation or decrementation should occur in their own toplevel statement to increase readability.
- A list of exceptions can be defined for this test.
With inner assignments it is difficult to see all places where a variable is set. With the exception of for iterators, all assignments should occur in their own toplevel statement to increase readability.
- A list of exceptions can be defined for this test.
Check that there is only one class declaration per PHP file.
Avoid using variable variables (like $$a).
$this cannot be used inside a static function.
Detect unused private functions (detecting unused public ones is more difficult).
Detect unused variables. This one is a bit experimental and can generate false positives (variables declared in one class and used in another one for example).
Detect unused function parameters. If the docBlocks of the function contains "@inheritdoc" then this check is disabled.
Detect unused code (after return or throw).
Example:
function foo {
// do something
return;
// do something else
}
Avoid using a count/sizeof function inside a loop.
Example:
while ($a < count($b)) {
// do something
}
Check for deprecated methods in PHP and propose some replacement.
Example:
split($a);
- Function split is deprecated since PHP 5.3, use explode($pattern, $string) or preg_split('@'.$pattern.'@', $string) instead
Check for the presence of comparison operators that should be replaced by strict comparisons.
Example:
if ($a != '0')
// should be
if ($a !== '0')
Check for methods that have been deprecated and are an alias of another method in PHP.
Example:
die;
// should be
exit()