
Converts simple usages of array_push($x, $y);
to $x[] = $y;
.
Converts backtick operators to shell_exec
calls.
Replace deprecated ereg
regular expression functions with preg
.
Replace non multibyte-safe functions with corresponding mb function.
Master functions shall be used instead of aliases.
Master language constructs shall be used instead of aliases.
Either language construct print
or echo
should be used.
Converts pow
to the **
operator.
Replaces rand
, srand
, getrandmax
functions calls with their mt_*
analogs.
Cast shall be used, not settype
.
PHP arrays should be declared using the configured syntax.
Operator =>
should not be surrounded by multi-line whitespaces.
PHP single-line arrays should not have trailing comma.
In array declaration, there MUST NOT be a whitespace before each comma.
Array index should always be written by using square braces.
PHP multi-line arrays should have a trailing comma.
Arrays should be formatted like function/method arguments, without leading or trailing single line space.
In array declaration, there MUST be a whitespace after each comma.
The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
PHP code MUST use only UTF-8 without BOM (remove BOM).
Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols.
Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name.
Class names should match the file name.
Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name.
The PHP constants true
, false
, and null
MUST be written using the correct casing.
The PHP constants true
, false
, and null
MUST be in lower case.
PHP keywords MUST be in lower case.
Class static references self
, static
and parent
MUST be in lower case.
Magic constants should be referred to using the correct casing.
Magic method definitions and calls must be using the correct casing.
Function defined by PHP should be called using the correct casing.
Native type hints for functions should use the correct case.
A single space or none should be between cast and variable.
Cast should be written in lower case.
Replaces intval
, floatval
, doubleval
, strval
and boolval
function calls with according type casting operator.
Short cast bool
using double exclamation mark should not be used.
Variables must be set null
instead of using (unset)
casting.
Cast (boolean)
and (integer)
should be written as (bool)
and (int)
, (double)
and (real)
as (float)
, (binary)
as (string)
.
Class, trait and interface elements must be separated with one or none blank line.
Whitespace around the keywords of a class, trait or interfaces definition should be one space.
All classes must be final, except abstract ones and Doctrine entities.
Internal classes should be final
.
All public
methods of abstract
classes should be final
.
Converts static
access to self
access in final
classes.
Methods must be separated with one blank line.
There should be no empty lines after class opening brace.
Properties MUST not be explicitly initialized with null
except when they have a type declaration (PHP 7.4).
Convert PHP4-style constructors to __construct
.
A final
class must not have final
methods and private
methods must not be final
.
Orders the elements of classes/interfaces/traits.
Orders the interfaces in an implements
or interface extends
clause.
Trait use
statements must be sorted alphabetically.
Converts protected
variables and methods to private
where possible.
Inside class or interface element self
should be preferred to the class name itself.
Inside a final
class or anonymous class self
should be preferred to static
.
There MUST NOT be more than one property or constant declared per statement.
Each trait use
must be done as single statement.
Visibility MUST be declared on all properties and methods; abstract
and final
MUST be declared before the visibility; static
MUST be declared after the visibility.
Class DateTimeImmutable
should be used instead of DateTime
.
Comments with annotation should be docblock when used on structural elements.
Single line comments should use double slashes //
and not hash #
.
Add, replace or remove header comment.
DocBlocks must start with two asterisks, multiline comments must start with a single asterisk, after the opening slash. Both must end with a single asterisk before the closing slash.
There should not be any empty comments.
There MUST be no trailing spaces inside comment or PHPDoc.
Single-line comments and multi-line comments with only one line of actual content should use the //
syntax.
Add leading \
before constant invocation of internal constant to speed up resolving. Constant name match is case-sensitive, except for null
, false
and true
.
The keyword elseif
should be used instead of else if
so that all control keywords look like single words.
Include/Require and file path should be divided with a single space. File path should not be placed under brackets.
Replace control structure alternative syntax to use braces.
There must be a comment when fall-through is intentional in a non-empty case body.
Replaces superfluous elseif
with if
.
Remove trailing commas in list function calls.
Removes unneeded parentheses around control statements.
Removes unneeded curly braces that are superfluous and aren’t part of a control structure’s body.
There should not be useless else
cases.
Simplify if
control structures that return the boolean result of their condition.
A case should be followed by a colon and not a semicolon.
Removes extra spaces between colon and case value.
Switch case must not be ended with continue
but with break
.
Write conditions in Yoda style (true
), non-Yoda style (['equal' => false, 'identical' => false, 'less_and_greater' => false]
) or ignore those conditions (null
) based on configuration.
Doctrine annotations must use configured operator for assignment in arrays.
Doctrine annotations without arguments must use the configured syntax.
Doctrine annotations must be indented with four spaces.
Fixes spaces in Doctrine annotations.
Replace multiple nested calls of dirname
by only one call with second $level
parameter. Requires PHP >= 7.0.
Order the flags in fopen
calls, b
and t
must be last.
The flags in fopen
calls must omit t
, and b
must be omitted or included consistently.
Spaces should be properly placed in a function declaration.
Ensure single space between function’s argument and its typehint.
Function implode
must be called with 2 arguments in the documented order.
Lambda must not import variables it doesn’t use.
In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.
Add leading \
before function invocation to speed up resolving.
When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
In function arguments there must not be arguments with default values before non-default ones.
There must be no sprintf
calls with only the first argument.
Adds or removes ?
before type declarations for parameters with a default null
value.
EXPERIMENTAL: Takes @param
annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
EXPERIMENTAL: Takes @return
annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
Callables must be called without using call_user_func*
when possible.
There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
Throwing exception must be done in single line.
Lambdas not (indirect) referencing $this
must be declared static
.
Anonymous functions with one-liner return statement must use arrow functions.
Add void
return type to functions with missing or empty return statements, but priority is given to @return
annotations. Requires PHP >= 7.1.
Transforms imported FQCN parameters and return types in function arguments to short version.
Imports or fully qualifies global classes/functions/constants.
There MUST be group use for the same namespaces.
Remove leading slashes in use
clauses.
Unused use
statements must be removed.
Ordering use
statements.
There MUST be one use keyword per declaration.
Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
Converts ::class
keywords to FQCN strings.
Using isset($var) &&
multiple times should be done in one call.
Calling unset
on multiple items should be done in one call.
Equal sign in declare statement should be surrounded by spaces or not following configuration.
Replaces dirname(__FILE__)
expression with equivalent __DIR__
constant.
Error control operator should be added to deprecation notices and/or removed from other cases.
Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0.
Replace core functions calls returning constants with the constants.
Replaces is_null($var)
expression with null === $var
.
Properties should be set to null
instead of using unset
.
Ensures deprecation notices are silenced.
Ensures a single space after language constructs.
List (array
destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.
There MUST be one blank line after the namespace declaration.
Namespace must not contain spacing, comments or PHPDoc.
There should be no blank lines before a namespace declaration.
The namespace declaration line shouldn’t contain leading whitespace.
There should be exactly one blank line before a namespace declaration.
Replace accidental usage of homoglyphs (non ascii characters) in names.
Binary operators should be surrounded by space as configured.
Concatenation should be spaced according configuration.
Pre- or post-increment and decrement operators should be used if possible.
Use &&
and ||
logical operators instead of and
and or
.
All instances created with new keyword must be followed by braces.
Logical NOT operators (!
) should have leading and trailing whitespaces.
Logical NOT operators (!
) should have one trailing whitespace.
There should not be space before or after object T_OBJECT_OPERATOR
->
.
Operators - when multiline - must always be at the beginning or at the end of the line.
Pre incrementation/decrementation should be used if possible.
Increment and decrement operators should be used if possible.
Replace all <>
with !=
.
Standardize spaces around ternary operator.
Use the Elvis operator ?:
where possible.
Use null
coalescing operator ??
where possible. Requires PHP >= 7.0.
Unary operators should be placed adjacent to their operands.
Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
Replaces short-echo <?=
with long format <?php echo
/<?php print
syntax, or vice-versa.
PHP code must use the long <?php
tags or short-echo <?=
tags and not other tag variations.
Ensure there is no code on the same line as the PHP open tag.
The closing ?>
tag MUST be omitted from files containing only PHP.
Replaces short-echo <?=
with long format <?php echo
syntax.
PHPUnit assertion method calls like ->assertSame(true, $foo)
should be written with dedicated method like ->assertTrue($foo)
.
PHPUnit assertions like assertInternalType
, assertFileExists
, should be used over assertTrue
.
PHPUnit assertions like assertIsArray
should be used over assertInternalType
.
Usages of ->setExpectedException*
methods MUST be replaced by ->expectException*
methods.
PHPUnit annotations should be a FQCNs including a root namespace.
All PHPUnit test classes should be marked as internal.
Enforce camel (or snake) case for PHPUnit test methods, following configuration.
Usages of ->getMock
and ->getMockWithoutInvokingTheOriginalConstructor
methods MUST be replaced by ->createMock
or ->createPartialMock
methods.
Usage of PHPUnit’s mock e.g. ->will($this->returnValue(..))
must be replaced by its shorter equivalent such as ->willReturn(...)
.
PHPUnit classes MUST be used in namespaced version, e.g. \PHPUnit\Framework\TestCase
instead of \PHPUnit_Framework_TestCase
.
Usages of @expectedException*
annotations MUST be replaced by ->setExpectedException*
methods.
Order @covers
annotation of PHPUnit tests.
Changes the visibility of the setUp()
and tearDown()
functions of PHPUnit to protected
, to match the PHPUnit TestCase.
All PHPUnit test cases should have @small
, @medium
or @large
annotation to enable run time limits.
PHPUnit methods like assertSame
should be used instead of assertEquals
.
Adds or removes @test annotations from tests, following configuration.
Calls to PHPUnit\Framework\TestCase
static methods must all be of the same type, either $this->
, self::
or static::
.
Adds a default @coversNothing
annotation to PHPUnit test classes that have no @covers*
annotation.
Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.
Configured annotations should be omitted from PHPDoc.
Renames PHPDoc tags.
There should not be blank lines between docblock and the documented element.
There should not be empty PHPDoc blocks.
Removes @param
, @return
and @var
tags that don’t provide any useful information.
PHPDoc should contain @param
for all params.
All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically.
PHPDoc annotation descriptions should not be a sentence.
Docblocks should have the same indentation as the documented subject.
Fix PHPDoc inline tags, make @inheritdoc
always inline.
Fixes PHPDoc inline tags.
Changes doc blocks from single to multi line, or reversed. Works for class constants, properties and methods only.
@access
annotations should be omitted from PHPDoc.
No alias PHPDoc tags should be used.
@return void
and @return null
annotations should be omitted from PHPDoc.
@package
and @subpackage
annotations should be omitted from PHPDoc.
Classy that does not inherit must not have @inheritdoc
tags.
Order phpdoc tags by value.
Annotations in PHPDoc should be ordered so that @param
annotations come first, then @throws
annotations, then @return
annotations.
The type of @return
annotations of methods returning a reference to itself must the configured one.
Scalar types should always be written in the same form. int
not integer
, bool
not boolean
, float
not real
or double
.
Annotations in PHPDoc should be grouped together so that annotations of the same type immediately follow each other, and annotations of a different type are separated by a single blank line.
Single line @var
PHPDoc should have proper spacing.
PHPDoc summary should end in either a full stop, exclamation mark, or question mark.
Fixes casing of PHPDoc tags.
Forces PHPDoc tags to be either regular annotations or inline.
Docblocks should only be used on structural elements.
Removes extra blank lines after summary and after description in PHPDoc.
PHPDoc should start and end with content, excluding the very first and last line of the docblocks.
The correct case must be used for standard PHP types in PHPDoc.
Sorts PHPDoc types.
@var
and @type
annotations must have type and name in the correct order.
@var
and @type
annotations of classy properties should not contain the name.
An empty line feed should precede a return statement.
There should not be an empty return
statement at the end of a function.
Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method.
A return statement wishing to return void
should not return null
.
Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
Remove useless (semicolon) statements.
Multi-line whitespace before closing semicolon are prohibited.
Single-line whitespace before closing semicolon are prohibited.
Instructions must be terminated with a semicolon.
Fix whitespace after a semicolon.
Force strict types declaration in all files. Requires PHP >= 7.0.
Comparisons should be strict.
Functions should be used with $strict
param set to true
.
Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.
Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.
Convert heredoc
to nowdoc
where possible.
There should not be a binary flag before strings.
There must be no trailing whitespace in strings.
Converts explicit variables in double-quoted strings and heredoc syntax from simple to complex format (${
to {$
).
Convert double quotes to single quotes for simple strings.
All multi-line strings must use correct line ending.
Each element of an array must be indented exactly once.
An empty line feed must precede any configured statement.
Remove extra spaces in a nullable typehint.
Heredoc/nowdoc content must be properly indented. Requires PHP >= 7.3.
Code MUST use configured indentation type.
All PHP files must use same line ending.
Method chaining MUST be properly indented. Method chaining with different levels of indentation is not supported.
Removes extra blank lines and/or blank lines following configuration.
Removes extra blank lines and/or blank lines following configuration.
There MUST NOT be spaces around offset braces.
There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
Remove trailing whitespace at the end of non-blank lines.
Remove trailing whitespace at the end of blank lines.
A PHP file without end tag must always end with a single empty line feed.