Shared coding conventions make it possible for a team to collaborate efficiently. This rule raises issues for failures to comply with formatting standard. The default parameter values conform to the PSR2 standard.
use FooClass; // Noncompliant; the "use" declaration should be placed after the "namespace" declaration
namespace Vendor\Package;
use FooClass; // Noncompliant; the "namespace" declaration should be followed by a blank line
$foo = 1; // Noncompliant; the "use" declaration should be followed by a blank line
class ClassA {// Noncompliant; an open curly brace should be at the beginning of a new line for classes and functions
function my_function(){ // Noncompliant; curly brace on wrong line
if ($firstThing)// Noncompliant; an open curly brace should be at the end of line for a control structure
{
...
}
if ($secondThing) {// Noncompliant; there should be exactly one space between the closing parenthesis and the opening curly brace
...
}
if($thirdThing) { // Noncompliant; there should be exactly one space between the control structure keyword and the opening parenthesis
...
}
else { // Noncompliant; the close curly brace and the next "else" (or "catch" or "finally") keyword should be located on the same line
...
}
try{ // Noncompliant; there should be exactly one space between the control structure keyword and the curly brace
...
} catch (Exception $e) {
}
analyse( $fruit ) ; // Noncompliant; there should not be any space after the opening parenthesis and before the closing parenthesis
for ($i = 0;$i < 10; $i++) { // Nomcompliant; there should be exactly one space after each ";" in the {{for}} statement
...
}
pressJuice($apply ,$orange); // Noncompliant; the comma should be followed by one space and not preceded by any
do_something (); // Noncompliant; there should not be any space after the method name
foreach ($fruits as $fruit_key => $fruit) { // Noncompliant; in the foreach statement there should be one space before and after "as" keyword and "=>" operator
...
}
}
}
class ClassB
extends ParentClass // Noncompliant; the class name and the "extends" / "implements" keyword should be on the same line
{
...
}
class ClassC extends ParentClass implements \ArrayAccess, \Countable,
\Serializable // Noncompliant; the list of implemented interfaces should be correctly indented
{
public function aVeryLongMethodName(ClassTypeHint $arg1, // Noncompliant; the arguments in a method declaration should be correctly indented
&$arg2, array $arg3 = []) {
$noArgs_longVars = function () use ($longVar1, // Noncompliant; the arguments in a function declaration should be correctly indented
$longerVar2,
$muchLongerVar3
) {
...
};
$foo->bar($longArgument, // Noncompliant; the arguments in a method call should be correctly indented
$longerArgument,
$muchLongerArgument); // Noncompliant; the closing parenthesis should be placed on the next line
$closureWithArgsAndVars = function($arg1, $arg2)use ($var1, $var2) { // Noncompliant; the closure declaration should be correctly spaced - see (5)