- All PSR-12 rules except for
declare(strict_types=1)
should be on the same line as PHP open tag.
declare(strict_types=1)
is required in all PHP files.
snake_case
is allowed in test method names
public function test_something(): void
{
}
- All classes should be declared as either
final
or abstract
// Prohibited.
// Should be declared as either final or abstract
class foobar
{
}
- Filenames must match the class names.
- Detect commented-out code.
// Will warn about the next line
// require_once $file;
- Ban some built-in functions:
sizeof
, use count
print
, use echo
each
, use foreach
is_null
, use === null
create_function
var_dump
print_r
debug_print_backtrace
eval
extract
- Brackets are not required when including a file.
// will warn you about this
require_once($file);
// brackets are not required
require_once $file;
- Align multiple statements
$var = 'value';
$longVarName = 'value';
- Array bracket spacing
$array ['key'] = 'value';
$array[ 'key'] = 'value';
$array['key' ] = 'value';
// Will be formatted to
$array['key'] = 'value';
$array['key'] = 'value';
$array['key'] = 'value';
- Multiline array indentation
function check(): void
{
return $myArray === [
'key1' => 'value',
'key-long-long-long' => 'value',
'key-medium' => 'value'
];
}
// Will be formatted to
function check(): void
{
return $myArray === [
'key1' => 'value',
'key-long-long-long' => 'value',
'key-medium' => 'value',
];
}
- Semi-colon spacing
$var = 'value' ;
// will be formatted to
$var = 'value';
- Language construct spacing
// For example
require$blah;
require_once 'test';
$a = new stdClass();
// will be formatted to
require $blah;
require_once 'test';
$a = new stdClass();
- Logical operator spacing
$a = $b && $c;
$a = $b && $c;
// will be formatted to
$a = $b && $c;
$a = $b && $c;
- Object operator spacing
$this ->testThis();
$this-> testThis();
parent ::testThis();
parent:: testThis();
// will be formatted to
$this->testThis();
$this->testThis();
parent::testThis();
parent::testThis();
- Cast spacing
(int)$var;
(int) $var;
// will be formatted to
(int) $var;
(int) $var;
- String concatenation spacing
$var = 'Hello' . ' World';
$var = 'Hello' . ' World';
$var = 'Hello' .
' World';
// will be formatted to
$var = 'Hello' . ' World';
$var = 'Hello' . ' World';
$var = 'Hello' . ' World';
- Echoed strings should not be bracketed
echo('Should not be bracketed');
// will be formatted to
echo 'Should not be bracketed';
- Double quote is used in escaped string only
echo "Double quote is not required here";
// will be formatted to
echo 'Double quote is not required here';
- Remove space before and after function body
function fn()
{
$var = 1;
}
// will be formatted to
function fn()
{
$var = 1;
}
- Spacing between functions
function fn1()
{
}
function fn2()
{
}
- Class member spacing
class Foo
{
private $foo;
private $bar;
}
- Support fluent interface
$obj->add('value 1')
->add('value 2')
->add('value 3');
- Disallow long array syntax
$arr = array(); // not allowedgit a
- Forbid final methods in final classes
- Remove unused
use
- Fully qualified global functions
- Disallow group
use
- Disallow multiple
use
per line
- Disallow
use
from same namespace
- Detect useless alias
- Reference used name only (
SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
)
- Detect useless variable declaration
- Detect unused variables
- Detect unused function parameters
- Detect unused inherited variables passed to a closure
- Disallow one-line property doc comment