this issue lists all sniffs currently implemented in this repository as described in the structure segment of the symfony coding standard.
this issue can be marked as resolved once the example class at the bottom triggers all mentioned errors when checked with this standard (be sure to remove all comment lines before checking).
<?php
namespace Symfony2;
// Declare the class inheritance and all the implemented interfaces on the same line as the class name
class Foo
extends Bar
implements Baz
{
// Add a comma after each array item in a multi-line array, even after the last one
private $a = [
'foo',
'bar'
];
// Add a single space after each comma delimiter
public function __construct($a,$b)
{
// Always use identical comparison unless you need type juggling
if ($a == $b) {
// Place unary operators (!, --, ...) adjacent to the affected variable
$a = $b++;
}
}
// Declare class properties before methods;
private $b;
// Declare public methods first, then protected ones and finally private ones.
protected function bar()
{
// Use parentheses when instantiating classes regardless of the number of arguments the constructor has
$foo = new Bar;
// Do not use spaces around [ offset accessor and before ] offset accessor.
$this->a [ 'foo' ] = $foo;
}
// Declare all the arguments on the same line as the method/function name, no matter how many arguments there are
public function baz(
$foo,
$bar
){
// Use Yoda conditions when checking a variable against an expression
if ($foo === 1) {
// Exception and error message strings must be concatenated using sprintf
throw new \Exception('Bar'.$foo);
// Do not use else, elseif, break after if and case conditions which return or throw something
} else {
// Add a single space around binary operators (==, &&, ...)
if ($foo===$bar) {
// Calls to trigger_error with type E_USER_DEPRECATED must be switched to opt-in via @ operator.
trigger_error('deprecation', E_USER_DEPRECATED);
}
}
}
public function foo($a, $b)
{
// Use braces to indicate control structure body regardless of the number of statements it contains;
if ($a === $b)
++$a;
// Add a blank line before return statements, unless the return is alone inside a statement-group (like an if statement);
return $b;
}
}
// Define one class per file
class Bar
{
}