-
Notifications
You must be signed in to change notification settings - Fork 10
Included TYPO3Flow CodeSniffs (with code examples)
- Array Bracket Spacing
- Self Member Reference
- Duplicate Class Names
- Unconditional If Statements
- Unnecessary Final Modifiers
- For Loops With Function Calls in the Test
- Empty Statements
- Inline Comments
- Inline Control Structures
- One Class Per File
- One Interface Per File
- Byte Order Marks
- Line Endings
- Opening Brace in Function Declarations
- Function Argument Spacing
- Constructor name
- Constant Names
- Opening Tag at Start of File
- PHP Code Tags
- Deprecated Functions
- PHP Constants
- ConcatenationSpacing
- Semicolon Spacing
When referencing arrays you should not put whitespace around the opening bracket or before the closing bracket.
| Valid: No spaces around the brackets. | Invalid: Spaces around the brackets. |
| $foo['bar']; | $foo [ 'bar' ]; |
The self keyword should be used instead of the current class name, should be lowercase, and should not have spaces before or after it.
| Valid: Lowercase self used. | Invalid: Uppercase self used. |
| self::foo(); | SELF::foo(); |
| Valid: Correct spacing used. | Invalid: Incorrect spacing used. |
| self::foo(); | self :: foo(); |
| Valid: Self used as reference. | Invalid: Local class name used as reference. |
| class Foo{ public static function bar() { } public static function baz() { self::bar(); }} | class Foo{ public static function bar() { } public static function baz() { Foo::bar(); }} |
Class and Interface names should be unique in a project. They should never be duplicated.
| Valid: A unique class name. | Invalid: A class duplicated (including across multiple files). |
| class Foo{} | class Foo{}class Foo{} |
If statements that are always evaluated should not be used.
| Valid: An if statement that only executes conditionally. | Invalid: An if statement that is always performed. |
| if ($test) { $var = 1;} | if (true) { $var = 1;} |
| Valid: An if statement that only executes conditionally. | Invalid: An if statement that is never performed. |
| if ($test) { $var = 1;} | if (false) { $var = 1;} |
Methods should not be declared final inside of classes that are declared final.
| Valid: A method in a final class is not marked final. | Invalid: A method in a final class is also marked final. |
| final class Foo{ public function bar() { }} | final class Foo{ public final function bar() { }} |
For loops should not call functions inside the test for the loop when they can be computed beforehand.
| Valid: A for loop that determines its end condition before the loop starts. | Invalid: A for loop that unnecessarily computes the same value on every iteration. |
| $end = count($foo);for ($i = 0; $i < $end; $i++) { echo $foo[$i]."\n";} | for ($i = 0; $i < count($foo); $i++) { echo $foo[$i]."\n";} |
Control Structures must have at least one statment inside of the body.
| Valid: There is a statement inside the control structure. | Invalid: The control structure has no statements. |
| if ($test) { $var = 1;} | if ($test) { // do nothing} |
Perl-style # comments are not allowed.
| Valid: A // style comment. | Invalid: A # style comment. |
| // A comment. | # A comment. |
Control Structures should use braces.
| Valid: Braces are used around the control structure. | Invalid: No braces are used for the control structure.. |
| if ($test) { $var = 1;} | if ($test) $var = 1; |
There should only be one class defined in a file.
| Valid: Only one class in the file. | Invalid: Multiple classes defined in one file. |
| <?phpclass Foo{} | <?phpclass Foo{}class Bar{} |
There should only be one interface defined in a file.
| Valid: Only one interface in the file. | Invalid: Multiple interfaces defined in one file. |
| <?phpinterface Foo{} | <?phpinterface Foo{}interface Bar{} |
Byte Order Marks that may corrupt your application should not be used. These include 0xefbbbf (UTF-8), 0xfeff (UTF-16 BE) and 0xfffe (UTF-16 LE).
Unix-style endlines are preferred ("\n" instead of "\r\n").
Function declarations follow the "Kernighan/Ritchie style". The function brace is on the same line as the function declaration. One space is required between the closing parenthesis and the brace.
| Valid: brace on same line | Invalid: brace on next line |
| function fooFunction($arg1, $arg2 = '') { ...} | function fooFunction($arg1, $arg2 = ''){ ...} |
Function arguments should have one space after a comma, and single spaces surrounding the equals sign for default values.
| Valid: Single spaces after a comma. | Invalid: No spaces after a comma. |
| function foo($bar, $baz){} | function foo($bar,$baz){} |
| Valid: Single spaces around an equals sign in function declaration. | Invalid: No spaces around an equals sign in function declaration. |
| function foo($bar, $baz = true){} | function foo($bar, $baz=true){} |
Constructors should be named __construct, not after the class.
| Valid: The constructor is named __construct. | Invalid: The old style class name constructor is used. |
| class Foo{ function __construct() { }} | class Foo{ function Foo() { }} |
Constants should always be all-uppercase, with underscores to separate words.
| Valid: all uppercase | Invalid: mixed case |
| define('FOO_CONSTANT', 'foo');class FooClass{ const FOO_CONSTANT = 'foo';} | define('Foo_Constant', 'foo');class FooClass{ const foo_constant = 'foo';} |
The opening php tag should be the first item in the file.
| Valid: A file starting with an opening php tag. | Invalid: A file with content before the opening php tag. |
| <?phpecho 'Foo'; | Beginning content<?phpecho 'Foo'; |
Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is the most portable way to include PHP code on differing operating systems and setups.
Deprecated functions should not be used.
| Valid: A non-deprecated function is used. | Invalid: A deprecated function is used. |
| $foo = explode('a', $bar); | $foo = split('a', $bar); |
The true, false and null constants must always be uppercase.
| Valid: uppercase constants | Invalid: lowercase constants |
| if ($var === FALSE || $var === NULL) { $var = TRUE;} | if ($var === false || $var === null) { $var = true;} |
This standard is about the spacing of concat strings
String concatenation operators must be surrounded by spaces
| Valid: String concatenation operator surrounded by space | Invalid: String concatenation operator is not surrounded by space |
| $content = 'Hello ' . 'world!'; | $content = 'Hello '. 'world!';$content = 'Hello ' .'world!';$content = 'Hello '.'world!'; |
String concatenation operators should be surrounded by only one space
| Valid: String concatenation operator surrounded by one space on every side | Invalid: String concatenation operator surrounded by multiple spaces |
| $content = 'Hello ' . 'world!'; | $content = 'Hello ' . 'world!';$content = 'Hello ' . 'world!'; |
Semicolons should not have spaces before them.
| Valid: No space before the semicolon. | Invalid: Space before the semicolon. |
| echo "hi"; | echo "hi" ; |
Documentation generated on Wed, 23 Jul 2014 13:08:16 +0200 by PHP_CodeSniffer 2.0.0a1