- array_push (risky)
- Converts simple usages of
array_push($x, $y);
to$x[] = $y;
.
- backtick_to_shell_exec
- Converts backtick operators to
shell_exec
calls.
- ereg_to_preg (risky)
- Replace deprecated
ereg
regular expression functions withpreg
.
- mb_str_functions (risky)
- Replace non multibyte-safe functions with corresponding mb function.
- no_alias_functions (risky)
- Master functions shall be used instead of aliases.
- no_alias_language_construct_call
- Master language constructs shall be used instead of aliases.
- no_mixed_echo_print
- Either language construct
print
orecho
should be used.
- pow_to_exponentiation (risky)
- Converts
pow
to the**
operator.
- random_api_migration (risky)
- Replaces
rand
,srand
,getrandmax
functions calls with theirmt_*
analogs.
- set_type_to_cast (risky)
- Cast shall be used, not
settype
.
- array_syntax
- PHP arrays should be declared using the configured syntax.
- no_multiline_whitespace_around_double_arrow
- Operator
=>
should not be surrounded by multi-line whitespaces.
- no_trailing_comma_in_singleline_array
- PHP single-line arrays should not have trailing comma.
- no_whitespace_before_comma_in_array
- In array declaration, there MUST NOT be a whitespace before each comma.
- normalize_index_brace
- Array index should always be written by using square braces.
- trailing_comma_in_multiline_array
- PHP multi-line arrays should have a trailing comma.
- trim_array_spaces
- Arrays should be formatted like function/method arguments, without leading or trailing single line space.
- whitespace_after_comma_in_array
- In array declaration, there MUST be a whitespace after each comma.
- braces
- The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
- encoding
- PHP code MUST use only UTF-8 without BOM (remove BOM).
- non_printable_character (risky)
- Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols.
- psr0 (deprecated, risky)
- 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.
- psr4 (deprecated, risky)
- Class names should match the file name.
- psr_autoloading (risky)
- 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.
- constant_case
- The PHP constants
true
,false
, andnull
MUST be written using the correct casing.
- lowercase_constants (deprecated)
- The PHP constants
true
,false
, andnull
MUST be in lower case.
- lowercase_keywords
- PHP keywords MUST be in lower case.
- lowercase_static_reference
- Class static references
self
,static
andparent
MUST be in lower case.
- magic_constant_casing
- Magic constants should be referred to using the correct casing.
- magic_method_casing
- Magic method definitions and calls must be using the correct casing.
- native_function_casing
- Function defined by PHP should be called using the correct casing.
- native_function_type_declaration_casing
- Native type hints for functions should use the correct case.
- cast_spaces
- A single space or none should be between cast and variable.
- lowercase_cast
- Cast should be written in lower case.
- modernize_types_casting (risky)
- Replaces
intval
,floatval
,doubleval
,strval
andboolval
function calls with according type casting operator.
- no_short_bool_cast
- Short cast
bool
using double exclamation mark should not be used.
- no_unset_cast
- Variables must be set
null
instead of using(unset)
casting.
- short_scalar_cast
- Cast
(boolean)
and(integer)
should be written as(bool)
and(int)
,(double)
and(real)
as(float)
,(binary)
as(string)
.
- class_attributes_separation
- Class, trait and interface elements must be separated with one or none blank line.
- class_definition
- Whitespace around the keywords of a class, trait or interfaces definition should be one space.
- final_class (risky)
- All classes must be final, except abstract ones and Doctrine entities.
- final_internal_class (risky)
- Internal classes should be
final
.
- final_public_method_for_abstract_class (risky)
- All
public
methods ofabstract
classes should befinal
.
- final_static_access (deprecated)
- Converts
static
access toself
access infinal
classes.
- method_separation (deprecated)
- Methods must be separated with one blank line.
- no_blank_lines_after_class_opening
- There should be no empty lines after class opening brace.
- no_null_property_initialization
- Properties MUST not be explicitly initialized with
null
except when they have a type declaration (PHP 7.4).
- no_php4_constructor (risky)
- Convert PHP4-style constructors to
__construct
.
- no_unneeded_final_method (risky)
- A
final
class must not havefinal
methods andprivate
methods must not befinal
.
- ordered_class_elements
- Orders the elements of classes/interfaces/traits.
- ordered_interfaces (risky)
- Orders the interfaces in an
implements
orinterface extends
clause.
- ordered_traits (risky)
- Trait
use
statements must be sorted alphabetically.
- protected_to_private
- Converts
protected
variables and methods toprivate
where possible.
- self_accessor (risky)
- Inside class or interface element
self
should be preferred to the class name itself.
- self_static_accessor
- Inside a
final
class or anonymous classself
should be preferred tostatic
.
- single_class_element_per_statement
- There MUST NOT be more than one property or constant declared per statement.
- single_trait_insert_per_statement
- Each trait
use
must be done as single statement.
- visibility_required
- Visibility MUST be declared on all properties and methods;
abstract
andfinal
MUST be declared before the visibility;static
MUST be declared after the visibility.
- date_time_immutable (risky)
- Class
DateTimeImmutable
should be used instead ofDateTime
.
- comment_to_phpdoc (risky)
- Comments with annotation should be docblock when used on structural elements.
- hash_to_slash_comment (deprecated)
- Single line comments should use double slashes
//
and not hash#
.
- header_comment
- Add, replace or remove header comment.
- multiline_comment_opening_closing
- 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.
- no_empty_comment
- There should not be any empty comments.
- no_trailing_whitespace_in_comment
- There MUST be no trailing spaces inside comment or PHPDoc.
- single_line_comment_style
- Single-line comments and multi-line comments with only one line of actual content should use the
//
syntax.
- native_constant_invocation (risky)
- Add leading
\
before constant invocation of internal constant to speed up resolving. Constant name match is case-sensitive, except fornull
,false
andtrue
.
- elseif
- The keyword
elseif
should be used instead ofelse if
so that all control keywords look like single words.
- include
- Include/Require and file path should be divided with a single space. File path should not be placed under brackets.
- no_alternative_syntax
- Replace control structure alternative syntax to use braces.
- no_break_comment
- There must be a comment when fall-through is intentional in a non-empty case body.
- no_superfluous_elseif
- Replaces superfluous
elseif
withif
.
- no_trailing_comma_in_list_call
- Remove trailing commas in list function calls.
- no_unneeded_control_parentheses
- Removes unneeded parentheses around control statements.
- no_unneeded_curly_braces
- Removes unneeded curly braces that are superfluous and aren't part of a control structure's body.
- no_useless_else
- There should not be useless
else
cases.
- simplified_if_return
- Simplify
if
control structures that return the boolean result of their condition.
- switch_case_semicolon_to_colon
- A case should be followed by a colon and not a semicolon.
- switch_case_space
- Removes extra spaces between colon and case value.
- switch_continue_to_break
- Switch case must not be ended with
continue
but withbreak
.
- yoda_style
- 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_annotation_array_assignment
- Doctrine annotations must use configured operator for assignment in arrays.
- doctrine_annotation_braces
- Doctrine annotations without arguments must use the configured syntax.
- doctrine_annotation_indentation
- Doctrine annotations must be indented with four spaces.
- doctrine_annotation_spaces
- Fixes spaces in Doctrine annotations.
- combine_nested_dirname (risky)
- Replace multiple nested calls of
dirname
by only one call with second$level
parameter. Requires PHP >= 7.0.
- fopen_flag_order (risky)
- Order the flags in
fopen
calls,b
andt
must be last.
- fopen_flags (risky)
- The flags in
fopen
calls must omitt
, andb
must be omitted or included consistently.
- function_declaration
- Spaces should be properly placed in a function declaration.
- function_typehint_space
- Ensure single space between function's argument and its typehint.
- implode_call (risky)
- Function
implode
must be called with 2 arguments in the documented order.
- lambda_not_used_import
- Lambda must not import variables it doesn't use.
- method_argument_space
- 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.
- native_function_invocation (risky)
- Add leading
\
before function invocation to speed up resolving.
- no_spaces_after_function_name
- When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
- no_unreachable_default_argument_value (risky)
- In function arguments there must not be arguments with default values before non-default ones.
- no_useless_sprintf (risky)
- There must be no
sprintf
calls with only the first argument.
- nullable_type_declaration_for_default_null_value
- Adds or removes
?
before type declarations for parameters with a defaultnull
value.
- phpdoc_to_param_type (risky)
- EXPERIMENTAL: Takes
@param
annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
- phpdoc_to_return_type (risky)
- EXPERIMENTAL: Takes
@return
annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
- regular_callable_call (risky)
- Callables must be called without using
call_user_func*
when possible.
- return_type_declaration
- There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
- single_line_throw
- Throwing exception must be done in single line.
- static_lambda (risky)
- Lambdas not (indirect) referencing
$this
must be declaredstatic
.
- use_arrow_functions (risky)
- Anonymous functions with one-liner return statement must use arrow functions.
- void_return (risky)
- Add
void
return type to functions with missing or empty return statements, but priority is given to@return
annotations. Requires PHP >= 7.1.
- fully_qualified_strict_types
- Transforms imported FQCN parameters and return types in function arguments to short version.
- global_namespace_import
- Imports or fully qualifies global classes/functions/constants.
- group_import
- There MUST be group use for the same namespaces.
- no_leading_import_slash
- Remove leading slashes in
use
clauses.
- no_unused_imports
- Unused
use
statements must be removed.
- ordered_imports
- Ordering
use
statements.
- single_import_per_statement
- There MUST be one use keyword per declaration.
- single_line_after_imports
- Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
- class_keyword_remove
- Converts
::class
keywords to FQCN strings.
- combine_consecutive_issets
- Using
isset($var) &&
multiple times should be done in one call.
- combine_consecutive_unsets
- Calling
unset
on multiple items should be done in one call.
- declare_equal_normalize
- Equal sign in declare statement should be surrounded by spaces or not following configuration.
- dir_constant (risky)
- Replaces
dirname(__FILE__)
expression with equivalent__DIR__
constant.
- error_suppression (risky)
- Error control operator should be added to deprecation notices and/or removed from other cases.
- explicit_indirect_variable
- Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0.
- function_to_constant (risky)
- Replace core functions calls returning constants with the constants.
- is_null (risky)
- Replaces
is_null($var)
expression withnull === $var
.
- no_unset_on_property (risky)
- Properties should be set to
null
instead of usingunset
.
- silenced_deprecation_error (deprecated, risky)
- Ensures deprecation notices are silenced.
- single_space_after_construct
- Ensures a single space after language constructs.
- list_syntax
- List (
array
destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.
- blank_line_after_namespace
- There MUST be one blank line after the namespace declaration.
- clean_namespace
- Namespace must not contain spacing, comments or PHPDoc.
- no_blank_lines_before_namespace
- There should be no blank lines before a namespace declaration.
- no_leading_namespace_whitespace
- The namespace declaration line shouldn't contain leading whitespace.
- single_blank_line_before_namespace
- There should be exactly one blank line before a namespace declaration.
- no_homoglyph_names (risky)
- Replace accidental usage of homoglyphs (non ascii characters) in names.
- binary_operator_spaces
- Binary operators should be surrounded by space as configured.
- concat_space
- Concatenation should be spaced according configuration.
- increment_style
- Pre- or post-increment and decrement operators should be used if possible.
- logical_operators (risky)
- Use
&&
and||
logical operators instead ofand
andor
.
- new_with_braces
- All instances created with new keyword must be followed by braces.
- not_operator_with_space
- Logical NOT operators (
!
) should have leading and trailing whitespaces.
- not_operator_with_successor_space
- Logical NOT operators (
!
) should have one trailing whitespace.
- object_operator_without_whitespace
- There should not be space before or after object
T_OBJECT_OPERATOR
->
.
- operator_linebreak
- Operators - when multiline - must always be at the beginning or at the end of the line.
- pre_increment (deprecated)
- Pre incrementation/decrementation should be used if possible.
- standardize_increment
- Increment and decrement operators should be used if possible.
- standardize_not_equals
- Replace all
<>
with!=
.
- ternary_operator_spaces
- Standardize spaces around ternary operator.
- ternary_to_elvis_operator (risky)
- Use the Elvis operator
?:
where possible.
- ternary_to_null_coalescing
- Use
null
coalescing operator??
where possible. Requires PHP >= 7.0.
- unary_operator_spaces
- Unary operators should be placed adjacent to their operands.
- blank_line_after_opening_tag
- Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
- echo_tag_syntax
- Replaces short-echo
<?=
with long format<?php echo
/<?php print
syntax, or vice-versa.
- full_opening_tag
- PHP code must use the long
<?php
tags or short-echo<?=
tags and not other tag variations.
- linebreak_after_opening_tag
- Ensure there is no code on the same line as the PHP open tag.
- no_closing_tag
- The closing
?>
tag MUST be omitted from files containing only PHP.
- no_short_echo_tag (deprecated)
- Replaces short-echo
<?=
with long format<?php echo
syntax.
- php_unit_construct (risky)
- PHPUnit assertion method calls like
->assertSame(true, $foo)
should be written with dedicated method like->assertTrue($foo)
.
- php_unit_dedicate_assert (risky)
- PHPUnit assertions like
assertInternalType
,assertFileExists
, should be used overassertTrue
.
- php_unit_dedicate_assert_internal_type (risky)
- PHPUnit assertions like
assertIsArray
should be used overassertInternalType
.
- php_unit_expectation (risky)
- Usages of
->setExpectedException*
methods MUST be replaced by->expectException*
methods.
- php_unit_fqcn_annotation
- PHPUnit annotations should be a FQCNs including a root namespace.
- php_unit_internal_class
- All PHPUnit test classes should be marked as internal.
- php_unit_method_casing
- Enforce camel (or snake) case for PHPUnit test methods, following configuration.
- php_unit_mock (risky)
- Usages of
->getMock
and->getMockWithoutInvokingTheOriginalConstructor
methods MUST be replaced by->createMock
or->createPartialMock
methods.
- php_unit_mock_short_will_return (risky)
- Usage of PHPUnit's mock e.g.
->will($this->returnValue(..))
must be replaced by its shorter equivalent such as->willReturn(...)
.
- php_unit_namespaced (risky)
- PHPUnit classes MUST be used in namespaced version, e.g.
\PHPUnit\Framework\TestCase
instead of\PHPUnit_Framework_TestCase
.
- php_unit_no_expectation_annotation (risky)
- Usages of
@expectedException*
annotations MUST be replaced by->setExpectedException*
methods.
- php_unit_ordered_covers (deprecated)
- Order
@covers
annotation of PHPUnit tests.
- php_unit_set_up_tear_down_visibility (risky)
- Changes the visibility of the
setUp()
andtearDown()
functions of PHPUnit toprotected
, to match the PHPUnit TestCase.
- php_unit_size_class
- All PHPUnit test cases should have
@small
,@medium
or@large
annotation to enable run time limits.
- php_unit_strict (risky)
- PHPUnit methods like
assertSame
should be used instead ofassertEquals
.
- php_unit_test_annotation (risky)
- Adds or removes @test annotations from tests, following configuration.
- php_unit_test_case_static_method_calls (risky)
- Calls to
PHPUnit\Framework\TestCase
static methods must all be of the same type, either$this->
,self::
orstatic::
.
- php_unit_test_class_requires_covers
- Adds a default
@coversNothing
annotation to PHPUnit test classes that have no@covers*
annotation.
- align_multiline_comment
- Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.
- general_phpdoc_annotation_remove
- Configured annotations should be omitted from PHPDoc.
- general_phpdoc_tag_rename
- Renames PHPDoc tags.
- no_blank_lines_after_phpdoc
- There should not be blank lines between docblock and the documented element.
- no_empty_phpdoc
- There should not be empty PHPDoc blocks.
- no_superfluous_phpdoc_tags
- Removes
@param
,@return
and@var
tags that don't provide any useful information.
- phpdoc_add_missing_param_annotation
- PHPDoc should contain
@param
for all params.
- phpdoc_align
- All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically.
- phpdoc_annotation_without_dot
- PHPDoc annotation descriptions should not be a sentence.
- phpdoc_indent
- Docblocks should have the same indentation as the documented subject.
- phpdoc_inline_tag (deprecated)
- Fix PHPDoc inline tags, make
@inheritdoc
always inline.
- phpdoc_inline_tag_normalizer
- Fixes PHPDoc inline tags.
- phpdoc_line_span
- Changes doc blocks from single to multi line, or reversed. Works for class constants, properties and methods only.
- phpdoc_no_access
@access
annotations should be omitted from PHPDoc.
- phpdoc_no_alias_tag
- No alias PHPDoc tags should be used.
- phpdoc_no_empty_return
@return void
and@return null
annotations should be omitted from PHPDoc.
- phpdoc_no_package
@package
and@subpackage
annotations should be omitted from PHPDoc.
- phpdoc_no_useless_inheritdoc
- Classy that does not inherit must not have
@inheritdoc
tags.
- phpdoc_order_by_value
- Order phpdoc tags by value.
- phpdoc_order
- Annotations in PHPDoc should be ordered so that
@param
annotations come first, then@throws
annotations, then@return
annotations.
- phpdoc_return_self_reference
- The type of
@return
annotations of methods returning a reference to itself must the configured one.
- phpdoc_scalar
- Scalar types should always be written in the same form.
int
notinteger
,bool
notboolean
,float
notreal
ordouble
.
- phpdoc_separation
- 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.
- phpdoc_single_line_var_spacing
- Single line
@var
PHPDoc should have proper spacing.
- phpdoc_summary
- PHPDoc summary should end in either a full stop, exclamation mark, or question mark.
- phpdoc_tag_casing
- Fixes casing of PHPDoc tags.
- phpdoc_tag_type
- Forces PHPDoc tags to be either regular annotations or inline.
- phpdoc_to_comment
- Docblocks should only be used on structural elements.
- phpdoc_trim_consecutive_blank_line_separation
- Removes extra blank lines after summary and after description in PHPDoc.
- phpdoc_trim
- PHPDoc should start and end with content, excluding the very first and last line of the docblocks.
- phpdoc_types
- The correct case must be used for standard PHP types in PHPDoc.
- phpdoc_types_order
- Sorts PHPDoc types.
- phpdoc_var_annotation_correct_order
@var
and@type
annotations must have type and name in the correct order.
- phpdoc_var_without_name
@var
and@type
annotations of classy properties should not contain the name.
- blank_line_before_return (deprecated)
- An empty line feed should precede a return statement.
- no_useless_return
- There should not be an empty
return
statement at the end of a function.
- return_assignment
- Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method.
- simplified_null_return
- A return statement wishing to return
void
should not returnnull
.
- multiline_whitespace_before_semicolons
- Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
- no_empty_statement
- Remove useless (semicolon) statements.
- no_multiline_whitespace_before_semicolons (deprecated)
- Multi-line whitespace before closing semicolon are prohibited.
- no_singleline_whitespace_before_semicolons
- Single-line whitespace before closing semicolon are prohibited.
- semicolon_after_instruction
- Instructions must be terminated with a semicolon.
- space_after_semicolon
- Fix whitespace after a semicolon.
- declare_strict_types (risky)
- Force strict types declaration in all files. Requires PHP >= 7.0.
- strict_comparison (risky)
- Comparisons should be strict.
- strict_param (risky)
- Functions should be used with
$strict
param set totrue
.
- escape_implicit_backslashes
- Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.
- explicit_string_variable
- Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.
- heredoc_to_nowdoc
- Convert
heredoc
tonowdoc
where possible.
- no_binary_string
- There should not be a binary flag before strings.
- no_trailing_whitespace_in_string (risky)
- There must be no trailing whitespace in strings.
- simple_to_complex_string_variable
- Converts explicit variables in double-quoted strings and heredoc syntax from simple to complex format (
${
to{$
).
- single_quote
- Convert double quotes to single quotes for simple strings.
- string_line_ending (risky)
- All multi-line strings must use correct line ending.
- array_indentation
- Each element of an array must be indented exactly once.
- blank_line_before_statement
- An empty line feed must precede any configured statement.
- compact_nullable_typehint
- Remove extra spaces in a nullable typehint.
- heredoc_indentation
- Heredoc/nowdoc content must be properly indented. Requires PHP >= 7.3.
- indentation_type
- Code MUST use configured indentation type.
- line_ending
- All PHP files must use same line ending.
- method_chaining_indentation
- Method chaining MUST be properly indented. Method chaining with different levels of indentation is not supported.
- no_extra_blank_lines
- Removes extra blank lines and/or blank lines following configuration.
- no_extra_consecutive_blank_lines (deprecated)
- Removes extra blank lines and/or blank lines following configuration.
- no_spaces_around_offset
- There MUST NOT be spaces around offset braces.
- no_spaces_inside_parenthesis
- There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
- no_trailing_whitespace
- Remove trailing whitespace at the end of non-blank lines.
- no_whitespace_in_blank_line
- Remove trailing whitespace at the end of blank lines.
- single_blank_line_at_eof
- A PHP file without end tag must always end with a single empty line feed.