-
Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.
Configuration options:
comment_type
Whether to fix PHPDoc comments only (phpdocs_only), any multi-line comment whose lines all start with an asterisk (phpdocs_like) or any multi-line comment (all_multiline).
Allowed values:'all_multiline'
,'phpdocs_like'
,'phpdocs_only'
Default value:'phpdocs_only'
Part of rule set @PhpCsFixer
-
Each element of an array must be indented exactly once.
Part of rule set @PhpCsFixer
-
Converts simple usages of
array_push($x, $y);
to$x[] = $y;
.warning risky Risky when the function
array_push
is overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
PHP arrays should be declared using the configured syntax.
Configuration options:
syntax
Whether to use the long or short array syntax.
Allowed values:'long'
,'short'
Default value:'short'
Part of rule sets @PHP54Migration @PHP70Migration @PHP71Migration @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration @PhpCsFixer @Symfony
assign_null_coalescing_to_coalesce_equal
Use the null coalescing assignment operator
??=
where possible.Part of rule sets @PHP74Migration @PHP80Migration @PHP81Migration
Source PhpCsFixer\Fixer\Operator\AssignNullCoalescingToCoalesceEqualFixer
-
Converts backtick operators to
shell_exec
calls.Conversion is done only when it is non risky, so when special chars like single-quotes, double-quotes and backticks are not used inside the command.
Part of rule sets @PhpCsFixer @Symfony
-
Binary operators should be surrounded by space as configured.
Configuration options:
default
Default fix strategy.
Allowed values:'align'
,'align_single_space'
,'align_single_space_minimal'
,'no_space'
,'single_space'
,null
Default value:'single_space'
operators
Dictionary of binary operator => fix strategy values that differ from the default strategy. Supported are: =, *, /, %, <, >, |, ^, +, -, &, &=, &&, ||, .=, /=, =>, ==, >=, ===, !=, <>, !==, <=, and, or, xor, -=, %=, *=, |=, +=, <<, <<=, >>, >>=, ^=, **, **=, <=>, ??, ??=
Allowed types:array
Default value:[]
Part of rule sets @PhpCsFixer @Symfony
-
There MUST be one blank line after the namespace declaration.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\NamespaceNotation\BlankLineAfterNamespaceFixer
-
Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer
-
An empty line feed must precede any configured statement.
Configuration options:
statements
List of statements which must be preceded by an empty line.
Allowed values: a subset of['break', 'case', 'continue', 'declare', 'default', 'phpdoc', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']
Default value:['break', 'continue', 'declare', 'return', 'throw', 'try']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer
-
The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
Configuration options:
allow_single_line_anonymous_class_with_empty_body
Whether single line anonymous class with empty body notation should be allowed.
Allowed types:bool
Default value:false
allow_single_line_closure
Whether single line lambda notation should be allowed.
Allowed types:bool
Default value:false
position_after_functions_and_oop_constructs
whether the opening brace should be placed on "next" or "same" line after classy constructs (non-anonymous classes, interfaces, traits, methods and non-lambda functions).
Allowed values:'next'
,'same'
Default value:'next'
position_after_control_structures
whether the opening brace should be placed on "next" or "same" line after control structures.
Allowed values:'next'
,'same'
Default value:'same'
position_after_anonymous_constructs
whether the opening brace should be placed on "next" or "same" line after anonymous constructs (anonymous classes and lambda functions).
Allowed values:'next'
,'same'
Default value:'same'
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
A single space or none should be between cast and variable.
Configuration options:
space
spacing to apply between cast and variable.
Allowed values:'none'
,'single'
Default value:'single'
Part of rule sets @PhpCsFixer @Symfony
-
Class, trait and interface elements must be separated with one or none blank line.
Configuration options:
elements
Dictionary of const|method|property|trait_import => none|one|only_if_meta values.
Allowed types:array
Default value:['const' => 'one', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer
-
Whitespace around the keywords of a class, trait or interfaces definition should be one space.
Configuration options:
multi_line_extends_each_single_line
Whether definitions should be multiline.
Allowed types:bool
Default value:false
single_item_single_line
Whether definitions should be single line when including a single item.
Allowed types:bool
Default value:false
single_line
Whether definitions should be single line.
Allowed types:bool
Default value:false
space_before_parenthesis
Whether there should be a single space after the parenthesis of anonymous class (PSR12) or not.
Allowed types:bool
Default value:false
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Converts
::class
keywords to FQCN strings.warning deprecated
Source PhpCsFixer\Fixer\LanguageConstruct\ClassKeywordRemoveFixer
-
Namespace must not contain spacing, comments or PHPDoc.
Part of rule sets @PHP80Migration @PHP81Migration @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\NamespaceNotation\CleanNamespaceFixer
-
Using
isset($var) &&
multiple times should be done in one call.Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer
-
Calling
unset
on multiple items should be done in one call.Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer
-
Replace multiple nested calls of
dirname
by only one call with second$level
parameter. Requires PHP >= 7.0.warning risky Risky when the function
dirname
is overridden.Part of rule sets @PHP70Migration:risky @PHP71Migration:risky @PHP74Migration:risky @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\FunctionNotation\CombineNestedDirnameFixer
-
Comments with annotation should be docblock when used on structural elements.
warning risky Risky as new docblocks might mean more, e.g. a Doctrine entity might have a new column in database.
Configuration options:
ignored_tags
List of ignored tags
Allowed types:array
Default value:[]
Part of rule set @PhpCsFixer:risky
-
Remove extra spaces in a nullable typehint.
Rule is applied only in a PHP 7.1+ environment.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer
-
Concatenation should be spaced according configuration.
Configuration options:
spacing
Spacing to apply around concatenation operator.
Allowed values:'none'
,'one'
Default value:'none'
Part of rule sets @PhpCsFixer @Symfony
-
The PHP constants
true
,false
, andnull
MUST be written using the correct casing.Configuration options:
case
Whether to use the upper or lower case syntax.
Allowed values:'lower'
,'upper'
Default value:'lower'
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
control_structure_continuation_position
Control structure continuation keyword must be on the configured line.
Configuration options:
position
the position of the keyword that continues the control structure.
Allowed values:'next_line'
,'same_line'
Default value:'same_line'
Source PhpCsFixer\Fixer\ControlStructure\ControlStructureContinuationPositionFixer
-
Class
DateTimeImmutable
should be used instead ofDateTime
.warning risky Risky when the code relies on modifying
DateTime
objects or if any of thedate_create*
functions are overridden. -
Equal sign in declare statement should be surrounded by spaces or not following configuration.
Configuration options:
space
Spacing to apply around the equal sign.
Allowed values:'none'
,'single'
Default value:'none'
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer
-
There must not be spaces around
declare
statement parentheses.Source PhpCsFixer\Fixer\LanguageConstruct\DeclareParenthesesFixer
-
Force strict types declaration in all files. Requires PHP >= 7.0.
warning risky Forcing strict types will stop non strict code from working.
Part of rule sets @PHP70Migration:risky @PHP71Migration:risky @PHP74Migration:risky @PHP80Migration:risky
-
Replaces
dirname(__FILE__)
expression with equivalent__DIR__
constant.warning risky Risky when the function
dirname
is overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
doctrine_annotation_array_assignment
Doctrine annotations must use configured operator for assignment in arrays.
Configuration options:
ignored_tags
List of tags that must not be treated as Doctrine Annotations.
Allowed types:array
Default value:['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']
operator
The operator to use.
Allowed values:':'
,'='
Default value:'='
Part of rule set @DoctrineAnnotation
Source PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationArrayAssignmentFixer
-
Doctrine annotations without arguments must use the configured syntax.
Configuration options:
ignored_tags
List of tags that must not be treated as Doctrine Annotations.
Allowed types:array
Default value:['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']
syntax
Whether to add or remove braces.
Allowed values:'with_braces'
,'without_braces'
Default value:'without_braces'
Part of rule set @DoctrineAnnotation
Source PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationBracesFixer
doctrine_annotation_indentation
Doctrine annotations must be indented with four spaces.
Configuration options:
ignored_tags
List of tags that must not be treated as Doctrine Annotations.
Allowed types:array
Default value:['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']
indent_mixed_lines
Whether to indent lines that have content before closing parenthesis.
Allowed types:bool
Default value:false
Part of rule set @DoctrineAnnotation
Source PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer
-
Fixes spaces in Doctrine annotations.
There must not be any space around parentheses; commas must be preceded by no space and followed by one space; there must be no space around named arguments assignment operator; there must be one space around array assignment operator.
Configuration options:
ignored_tags
List of tags that must not be treated as Doctrine Annotations.
Allowed types:array
Default value:['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']
around_parentheses
Whether to fix spaces around parentheses.
Allowed types:bool
Default value:true
around_commas
Whether to fix spaces around commas.
Allowed types:bool
Default value:true
before_argument_assignments
Whether to add, remove or ignore spaces before argument assignment operator.
Allowed types:null
,bool
Default value:false
after_argument_assignments
Whether to add, remove or ignore spaces after argument assignment operator.
Allowed types:null
,bool
Default value:false
before_array_assignments_equals
Whether to add, remove or ignore spaces before array = assignment operator.
Allowed types:null
,bool
Default value:true
after_array_assignments_equals
Whether to add, remove or ignore spaces after array assignment = operator.
Allowed types:null
,bool
Default value:true
before_array_assignments_colon
Whether to add, remove or ignore spaces before array : assignment operator.
Allowed types:null
,bool
Default value:true
after_array_assignments_colon
Whether to add, remove or ignore spaces after array assignment : operator.
Allowed types:null
,bool
Default value:true
Part of rule set @DoctrineAnnotation
Source PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationSpacesFixer
-
Replaces short-echo
<?=
with long format<?php echo
/<?php print
syntax, or vice-versa.Configuration options:
format
The desired language construct.
Allowed values:'long'
,'short'
Default value:'long'
long_function
The function to be used to expand the short echo tags
Allowed values:'echo'
,'print'
Default value:'echo'
shorten_simple_statements_only
Render short-echo tags only in case of simple code
Allowed types:bool
Default value:true
Part of rule sets @PhpCsFixer @Symfony
-
The keyword
elseif
should be used instead ofelse if
so that all control keywords look like single words.Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Empty loop-body must be in configured style.
Configuration options:
style
Style of empty loop-bodies.
Allowed values:'braces'
,'semicolon'
Default value:'semicolon'
Part of rule sets @PhpCsFixer @Symfony
-
Empty loop-condition must be in configured style.
Configuration options:
style
Style of empty loop-condition.
Allowed values:'for'
,'while'
Default value:'while'
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\EmptyLoopConditionFixer
-
PHP code MUST use only UTF-8 without BOM (remove BOM).
Part of rule sets @PSR1 @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Replace deprecated
ereg
regular expression functions withpreg
.warning risky Risky if the
ereg
function is overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Error control operator should be added to deprecation notices and/or removed from other cases.
warning risky Risky because adding/removing
@
might cause changes to code behaviour or iftrigger_error
function is overridden.Configuration options:
mute_deprecation_error
Whether to add @ in deprecation notices.
Allowed types:bool
Default value:true
noise_remaining_usages
Whether to remove @ in remaining usages.
Allowed types:bool
Default value:false
noise_remaining_usages_exclude
List of global functions to exclude from removing @
Allowed types:array
Default value:[]
Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\LanguageConstruct\ErrorSuppressionFixer
-
Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.
In PHP double-quoted strings and heredocs some chars like
n
,$
oru
have special meanings if preceded by a backslash (and some are special only if followed by other special chars), while a backslash preceding other chars are interpreted like a plain backslash. The precise list of those special chars is hard to remember and to identify quickly: this fixer escapes backslashes that do not start a special interpretation with the char after them. It is possible to fix also single-quoted strings: in this case there is no special chars apart from single-quote and backslash itself, so the fixer simply ensure that all backslashes are escaped. Both single and double backslashes are allowed in single-quoted strings, so the purpose in this context is mainly to have a uniformed way to have them written all over the codebase.Configuration options:
single_quoted
Whether to fix single-quoted strings.
Allowed types:bool
Default value:false
double_quoted
Whether to fix double-quoted strings.
Allowed types:bool
Default value:true
heredoc_syntax
Whether to fix heredoc syntax.
Allowed types:bool
Default value:true
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\StringNotation\EscapeImplicitBackslashesFixer
-
Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0.
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer
-
Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.
The reasoning behind this rule is the following: - When there are two valid ways of doing the same thing, using both is confusing, there should be a coding standard to follow - PHP manual marks"$var"
syntax as implicit and"${var}"
syntax as explicit: explicit code should always be preferred - Explicit syntax allows word concatenation inside strings, e.g."${var}IsAVar"
, implicit doesn't- Explicit syntax is easier to detect for IDE/editors and therefore has colors/highlight with higher contrast, which is easier to read Backtick operator is skipped because it is harder to handle; you can use
backtick_to_shell_exec
fixer to normalize backticks to stringsPart of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer
-
All classes must be final, except abstract ones and Doctrine entities.
No exception and no configuration are intentional. Beside Doctrine entities and of course abstract classes, there is no single reason not to declare all classes final. If you want to subclass a class, mark the parent class as abstract and create two child classes, one empty if necessary: you'll gain much more fine grained type-hinting. If you need to mock a standalone class, create an interface, or maybe it's a value-object that shouldn't be mocked at all. If you need to extend a standalone class, create an interface and use the Composite pattern. If you aren't ready yet for serious OOP, go with FinalInternalClassFixer, it's fine.
warning risky Risky when subclassing non-abstract classes.
-
Internal classes should be
final
.warning risky Changing classes to
final
might cause code execution to break.Configuration options:
annotation_include
Class level annotations tags that must be set in order to fix the class. (case insensitive)
Allowed types:array
Default value:['@internal']
annotation_exclude
Class level annotations tags that must be omitted to fix the class, even if all of the white list ones are used as well. (case insensitive)
Allowed types:array
Default value:['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity', '@Document', '@ODM\\Document']
consider_absent_docblock_as_internal_class
Should classes without any DocBlock be fixed to final?
Allowed types:bool
Default value:false
Part of rule set @PhpCsFixer:risky
Source PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer
final_public_method_for_abstract_class
All
public
methods ofabstract
classes should befinal
.Enforce API encapsulation in an inheritance architecture. If you want to override a method, use the Template method pattern.
warning risky Risky when overriding
public
methods ofabstract
classes.Source PhpCsFixer\Fixer\ClassNotation\FinalPublicMethodForAbstractClassFixer
-
The flags in
fopen
calls must omitt
, andb
must be omitted or included consistently.warning risky Risky when the function
fopen
is overridden.Configuration options:
b_mode
The b flag must be used (true) or omitted (false).
Allowed types:bool
Default value:true
Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Order the flags in
fopen
calls,b
andt
must be last.warning risky Risky when the function
fopen
is overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\FunctionNotation\FopenFlagOrderFixer
-
Transforms imported FQCN parameters and return types in function arguments to short version.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer
-
PHP code must use the long
<?php
tags or short-echo<?=
tags and not other tag variations.Part of rule sets @PSR1 @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Spaces should be properly placed in a function declaration.
Configuration options:
closure_function_spacing
Spacing to use before open parenthesis for closures.
Allowed values:'none'
,'one'
Default value:'one'
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer
-
Replace core functions calls returning constants with the constants.
warning risky Risky when any of the configured functions to replace are overridden.
Configuration options:
functions
List of function names to fix.
Allowed values: a subset of['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']
Default value:['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']
Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer
-
Ensure single space between function's argument and its typehint.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer
general_phpdoc_annotation_remove
Configured annotations should be omitted from PHPDoc.
Configuration options:
annotations
List of annotations to remove, e.g. ["author"].
Allowed types:array
Default value:[]
Source PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer
-
Renames PHPDoc tags.
Configuration options:
fix_annotation
Whether annotation tags should be fixed.
Allowed types:bool
Default value:true
fix_inline
Whether inline tags should be fixed.
Allowed types:bool
Default value:true
replacements
A map of tags to replace.
Allowed types:array
Default value:[]
case_sensitive
Whether tags should be replaced only if they have exact same casing.
Allowed types:bool
Default value:false
Part of rule sets @PhpCsFixer @Symfony
-
Replace
get_class
calls on object variables with class keyword syntax.warning risky Risky if the
get_class
function is overridden.Part of rule set @PHP80Migration:risky
Source PhpCsFixer\Fixer\LanguageConstruct\GetClassToClassKeywordFixer
-
Imports or fully qualifies global classes/functions/constants.
Configuration options:
import_constants
Whether to import, not import or ignore global constants.
Allowed values:false
,null
,true
Default value:null
import_functions
Whether to import, not import or ignore global functions.
Allowed values:false
,null
,true
Default value:null
import_classes
Whether to import, not import or ignore global classes.
Allowed values:false
,null
,true
Default value:true
-
There MUST be group use for the same namespaces.
-
Add, replace or remove header comment.
Configuration options:
header
Proper header content.
Allowed types:string
This option is required.comment_type
Comment syntax type.
Allowed values:'comment'
,'PHPDoc'
Default value:'comment'
location
The location of the inserted header.
Allowed values:'after_declare_strict'
,'after_open'
Default value:'after_declare_strict'
separate
Whether the header should be separated from the file content with a new line.
Allowed values:'both'
,'bottom'
,'none'
,'top'
Default value:'both'
-
Heredoc/nowdoc content must be properly indented. Requires PHP >= 7.3.
Configuration options:
indentation
Whether the indentation should be the same as in the start token line or one level more.
Allowed values:'same_as_start'
,'start_plus_one'
Default value:'start_plus_one'
Part of rule sets @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration
-
Convert
heredoc
tonowdoc
where possible.Part of rule set @PhpCsFixer
-
Function
implode
must be called with 2 arguments in the documented order.warning risky Risky when the function
implode
is overridden.Part of rule sets @PHP74Migration:risky @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
-
Include/Require and file path should be divided with a single space. File path should not be placed under brackets.
Part of rule sets @PhpCsFixer @Symfony
-
Pre- or post-increment and decrement operators should be used if possible.
Configuration options:
style
Whether to use pre- or post-increment and decrement operators.
Allowed values:'post'
,'pre'
Default value:'pre'
Part of rule sets @PhpCsFixer @Symfony
-
Code MUST use configured indentation type.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Integer literals must be in correct case.
Part of rule sets @PhpCsFixer @Symfony
-
Replaces
is_null($var)
expression withnull === $var
.warning risky Risky when the function
is_null
is overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Lambda must not import variables it doesn't use.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer
-
Ensure there is no code on the same line as the PHP open tag.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\PhpTag\LinebreakAfterOpeningTagFixer
-
All PHP files must use same line ending.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
List (
array
destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.Configuration options:
syntax
Whether to use the long or short list syntax.
Allowed values:'long'
,'short'
Default value:'short'
Part of rule sets @PHP71Migration @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration
-
Use
&&
and||
logical operators instead ofand
andor
.warning risky Risky, because you must double-check if using and/or with lower precedence was intentional.
Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Cast should be written in lower case.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
-
PHP keywords MUST be in lower case.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Class static references
self
,static
andparent
MUST be in lower case.Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer
-
Magic constants should be referred to using the correct casing.
Part of rule sets @PhpCsFixer @Symfony
-
Magic method definitions and calls must be using the correct casing.
Part of rule sets @PhpCsFixer @Symfony
-
Replace non multibyte-safe functions with corresponding mb function.
warning risky Risky when any of the functions are overridden, or when relying on the string byte size rather than its length in characters.
-
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.
Configuration options:
keep_multiple_spaces_after_comma
Whether keep multiple spaces after comma.
Allowed types:bool
Default value:false
on_multiline
Defines how to handle function arguments lists that contain newlines.
Allowed values:'ensure_fully_multiline'
,'ensure_single_line'
,'ignore'
Default value:'ensure_fully_multiline'
after_heredoc
Whether the whitespace between heredoc end and comma should be removed.
Allowed types:bool
Default value:false
Part of rule sets @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer
-
Method chaining MUST be properly indented. Method chaining with different levels of indentation is not supported.
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer
-
Replace
strpos()
calls withstr_starts_with()
orstr_contains()
if possible.warning risky Risky if
strpos
,str_starts_with
orstr_contains
functions are overridden.Part of rule set @PHP80Migration:risky
-
Replaces
intval
,floatval
,doubleval
,strval
andboolval
function calls with according type casting operator.warning risky Risky if any of the functions
intval
,floatval
,doubleval
,strval
orboolval
are overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer
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.
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\Comment\MultilineCommentOpeningClosingFixer
multiline_whitespace_before_semicolons
Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
Configuration options:
strategy
Forbid multi-line whitespace or move the semicolon to the new line for chained calls.
Allowed values:'new_line_for_chained_calls'
,'no_multi_line'
Default value:'no_multi_line'
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer
-
Add leading
\
before constant invocation of internal constant to speed up resolving. Constant name match is case-sensitive, except fornull
,false
andtrue
.warning risky Risky when any of the constants are namespaced or overridden.
Configuration options:
fix_built_in
Whether to fix constants returned by get_defined_constants. User constants are not accounted in this list and must be specified in the include one.
Allowed types:bool
Default value:true
include
List of additional constants to fix.
Allowed types:array
Default value:[]
exclude
List of constants to ignore.
Allowed types:array
Default value:['null', 'false', 'true']
scope
Only fix constant invocations that are made within a namespace or fix all.
Allowed values:'all'
,'namespaced'
Default value:'all'
strict
Whether leading `` of constant invocation not meant to have it should be removed.
Allowed types:bool
Default value:true
Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer
-
Function defined by PHP should be called using the correct casing.
Part of rule sets @PhpCsFixer @Symfony
-
Add leading
\
before function invocation to speed up resolving.warning risky Risky when any of the functions are overridden.
Configuration options:
exclude
List of functions to ignore.
Allowed types:array
Default value:[]
include
List of function names or sets to fix. Defined sets are @internal (all native functions), @all (all global functions) and @compiler_optimized (functions that are specially optimized by Zend).
Allowed types:array
Default value:['@compiler_optimized']
scope
Only fix function calls that are made within a namespace or fix all.
Allowed values:'all'
,'namespaced'
Default value:'all'
strict
Whether leading `` of function call not meant to have it should be removed.
Allowed types:bool
Default value:true
Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer
native_function_type_declaration_casing
Native type hints for functions should use the correct case.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer
-
All instances created with new keyword must be followed by braces.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
-
Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols.
warning risky Risky when strings contain intended invisible characters.
Configuration options:
use_escape_sequences_in_strings
Whether characters should be replaced with escape sequences in strings.
Allowed types:bool
Default value:true
Part of rule sets @PHP70Migration:risky @PHP71Migration:risky @PHP74Migration:risky @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
-
Array index should always be written by using square braces.
Part of rule sets @PHP74Migration @PHP80Migration @PHP81Migration @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer
-
Logical NOT operators (
!
) should have leading and trailing whitespaces. not_operator_with_successor_space
Logical NOT operators (
!
) should have one trailing whitespace.Source PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer
-
Master functions shall be used instead of aliases.
warning risky Risky when any of the alias functions are overridden.
Configuration options:
sets
List of sets to fix. Defined sets are:
- @all (all listed sets)
- @internal (native functions)
- @exif (EXIF functions)
- @ftp (FTP functions)
- @IMAP (IMAP functions)
- @ldap (LDAP functions)
- @mbreg (from ext-mbstring)
- @mysqli (mysqli functions)
- @oci (oci functions)
- @odbc (odbc functions)
- @openssl (openssl functions)
- @pcntl (PCNTL functions)
- @pg (pg functions)
- @posix (POSIX functions)
- @snmp (SNMP functions)
- @sodium (libsodium functions)
@time (time functions)
Allowed values: a subset of['@all', '@internal', '@exif', '@ftp', '@IMAP', '@ldap', '@mbreg', '@mysqli', '@oci', '@odbc', '@openssl', '@pcntl', '@pg', '@posix', '@snmp', '@sodium', '@time']
Default value:['@internal', '@IMAP', '@pg']
Part of rule sets @PHP74Migration:risky @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
no_alias_language_construct_call
Master language constructs shall be used instead of aliases.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Alias\NoAliasLanguageConstructCallFixer
-
Replace control structure alternative syntax to use braces.
Configuration options:
fix_non_monolithic_code
Whether to also fix code with inline HTML.
Allowed types:bool
Default value:true
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\NoAlternativeSyntaxFixer
-
There should not be a binary flag before strings.
Part of rule sets @PhpCsFixer @Symfony
no_blank_lines_after_class_opening
There should be no empty lines after class opening brace.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer
-
There should not be blank lines between docblock and the documented element.
Part of rule sets @PhpCsFixer @Symfony
no_blank_lines_before_namespace
There should be no blank lines before a namespace declaration.
Source PhpCsFixer\Fixer\NamespaceNotation\NoBlankLinesBeforeNamespaceFixer
-
There must be a comment when fall-through is intentional in a non-empty case body.
Adds a "no break" comment before fall-through cases, and removes it if there is no fall-through.
Configuration options:
comment_text
The text to use in the added comment and to detect it.
Allowed types:string
Default value:'no break'
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\NoBreakCommentFixer
-
The closing
?>
tag MUST be omitted from files containing only PHP.Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
There should not be any empty comments.
Part of rule sets @PhpCsFixer @Symfony
-
There should not be empty PHPDoc blocks.
Part of rule sets @PhpCsFixer @Symfony
-
Remove useless (semicolon) statements.
Part of rule sets @PhpCsFixer @Symfony
-
Removes extra blank lines and/or blank lines following configuration.
Configuration options:
tokens
List of tokens to fix.
Allowed values: a subset of['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']
Default value:['extra']
Part of rule sets @PhpCsFixer @Symfony
-
Replace accidental usage of homoglyphs (non ascii characters) in names.
warning risky Renames classes and cannot rename the files. You might have string references to renamed code (
$$name
).Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Remove leading slashes in
use
clauses.Part of rule sets @PSR12 @PhpCsFixer @Symfony
no_leading_namespace_whitespace
The namespace declaration line shouldn't contain leading whitespace.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer
-
Either language construct
print
orecho
should be used.Configuration options:
use
The desired language construct.
Allowed values:'echo'
,'print'
Default value:'echo'
Part of rule sets @PhpCsFixer @Symfony
no_multiline_whitespace_around_double_arrow
Operator
=>
should not be surrounded by multi-line whitespaces.Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer
no_null_property_initialization
Properties MUST not be explicitly initialized with
null
except when they have a type declaration (PHP 7.4).Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer
-
Convert PHP4-style constructors to
__construct
.warning risky Risky when old style constructor being fixed is overridden or overrides parent one.
Part of rule sets @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\ClassNotation\NoPhp4ConstructorFixer
-
Short cast
bool
using double exclamation mark should not be used.Part of rule sets @PhpCsFixer @Symfony
no_singleline_whitespace_before_semicolons
Single-line whitespace before closing semicolon are prohibited.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer
-
When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\NoSpacesAfterFunctionNameFixer
-
There MUST NOT be spaces around offset braces.
Configuration options:
positions
Whether spacing should be fixed inside and/or outside the offset braces.
Allowed values: a subset of['inside', 'outside']
Default value:['inside', 'outside']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer
-
There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\NoSpacesInsideParenthesisFixer
-
There must be no space around double colons (also called Scope Resolution Operator or Paamayim Nekudotayim).
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Operator\NoSpaceAroundDoubleColonFixer
-
Replaces superfluous
elseif
withif
.Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\ControlStructure\NoSuperfluousElseifFixer
-
Removes
@param
,@return
and@var
tags that don't provide any useful information.Configuration options:
allow_mixed
Whether type mixed without description is allowed (true) or considered superfluous (false)
Allowed types:bool
Default value:false
remove_inheritdoc
Remove @inheritDoc tags
Allowed types:bool
Default value:false
allow_unused_params
Whether param annotation without actual signature is allowed (true) or considered superfluous (false)
Allowed types:bool
Default value:false
Part of rule sets @PhpCsFixer @Symfony
no_trailing_comma_in_list_call
Remove trailing commas in list function calls.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer
no_trailing_comma_in_singleline_array
PHP single-line arrays should not have trailing comma.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer
-
Remove trailing whitespace at the end of non-blank lines.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer
no_trailing_whitespace_in_comment
There MUST be no trailing spaces inside comment or PHPDoc.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer
no_trailing_whitespace_in_string
There must be no trailing whitespace in strings.
warning risky Changing the whitespaces in strings might affect string comparisons and outputs.
Part of rule sets @PSR12:risky @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\StringNotation\NoTrailingWhitespaceInStringFixer
no_unneeded_control_parentheses
Removes unneeded parentheses around control statements.
Configuration options:
statements
List of control statements to fix.
Allowed values: a subset of['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']
Default value:['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer
-
Removes unneeded curly braces that are superfluous and aren't part of a control structure's body.
Configuration options:
namespaces
Remove unneeded curly braces from bracketed namespaces.
Allowed types:bool
Default value:false
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\NoUnneededCurlyBracesFixer
-
A
final
class must not havefinal
methods andprivate
methods must not befinal
.warning risky Risky when child class overrides a
private
method.Configuration options:
private_methods
Private methods of non-final classes must not be declared final.
Allowed types:bool
Default value:true
Part of rule sets @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\ClassNotation\NoUnneededFinalMethodFixer
no_unreachable_default_argument_value
In function arguments there must not be arguments with default values before non-default ones.
warning risky Modifies the signature of functions; therefore risky when using systems (such as some Symfony components) that rely on those (for example through reflection).
Part of rule sets @PHP80Migration:risky @PSR12:risky @PhpCsFixer:risky
Source PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer
-
Variables must be set
null
instead of using(unset)
casting.Part of rule sets @PHP80Migration @PHP81Migration @PhpCsFixer @Symfony
-
Properties should be set to
null
instead of usingunset
.warning risky Risky when relying on attributes to be removed using
unset
rather than be set tonull
. Changing variables tonull
instead of unsetting means these still show up when looping over class variables and reference properties remain unbroken. With PHP 7.4, this rule might introducenull
assignments to properties whose type declaration does not allow it.Part of rule set @PhpCsFixer:risky
Source PhpCsFixer\Fixer\LanguageConstruct\NoUnsetOnPropertyFixer
-
Unused
use
statements must be removed.Part of rule sets @PhpCsFixer @Symfony
-
There should not be useless
else
cases.Part of rule set @PhpCsFixer
-
There should not be an empty
return
statement at the end of a function.Part of rule set @PhpCsFixer
-
There must be no
sprintf
calls with only the first argument.warning risky Risky when if the
sprintf
function is overridden.Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer
no_whitespace_before_comma_in_array
In array declaration, there MUST NOT be a whitespace before each comma.
Configuration options:
after_heredoc
Whether the whitespace between heredoc end and comma should be removed.
Allowed types:bool
Default value:false
Part of rule sets @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer
-
Remove trailing whitespace at the end of blank lines.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer
nullable_type_declaration_for_default_null_value
Adds or removes
?
before type declarations for parameters with a defaultnull
value.Rule is applied only in a PHP 7.1+ environment.
Configuration options:
use_nullable_type_declaration
Whether to add or remove ? before type declarations for parameters with a default null value.
Allowed types:bool
Default value:true
Source PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer
object_operator_without_whitespace
There should not be space before or after object operators
->
and?->
.Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer
-
Literal octal must be in
0o
notation.Part of rule set @PHP81Migration
-
Operators - when multiline - must always be at the beginning or at the end of the line.
Configuration options:
only_booleans
whether to limit operators to only boolean ones
Allowed types:bool
Default value:false
position
whether to place operators at the beginning or at the end of the line
Allowed values:'beginning'
,'end'
Default value:'beginning'
Part of rule set @PhpCsFixer
-
Orders the elements of classes/interfaces/traits.
Configuration options:
order
List of strings defining order of elements.
Allowed values: a subset of['use_trait', 'public', 'protected', 'private', 'constant', 'constant_public', 'constant_protected', 'constant_private', 'property', 'property_static', 'property_public', 'property_protected', 'property_private', 'property_public_readonly', 'property_protected_readonly', 'property_private_readonly', 'property_public_static', 'property_protected_static', 'property_private_static', 'method', 'method_abstract', 'method_static', 'method_public', 'method_protected', 'method_private', 'method_public_abstract', 'method_protected_abstract', 'method_public_abstract_static', 'method_protected_abstract_static', 'method_public_static', 'method_protected_static', 'method_private_static', 'construct', 'destruct', 'magic', 'phpunit']
Default value:['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private']
sort_algorithm
How multiple occurrences of same type statements should be sorted
Allowed values:'alpha'
,'none'
Default value:'none'
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
-
Ordering
use
statements.Configuration options:
sort_algorithm
whether the statements should be sorted alphabetically or by length, or not sorted
Allowed values:'alpha'
,'length'
,'none'
Default value:'alpha'
imports_order
Defines the order of import types.
Allowed types:array
,null
Default value:null
Part of rule sets @PSR12 @PhpCsFixer @Symfony
-
Orders the interfaces in an
implements
orinterface extends
clause.warning risky Risky for
implements
when specifying both an interface and its parent interface, because PHP doesn't break onparent, child
but does onchild, parent
.Configuration options:
order
How the interfaces should be ordered
Allowed values:'alpha'
,'length'
Default value:'alpha'
direction
Which direction the interfaces should be ordered
Allowed values:'ascend'
,'descend'
Default value:'ascend'
Source PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer
-
Trait
use
statements must be sorted alphabetically.warning risky Risky when depending on order of the imports.
Part of rule sets @PhpCsFixer:risky @Symfony:risky
phpdoc_add_missing_param_annotation
PHPDoc should contain
@param
for all params.Configuration options:
only_untyped
Whether to add missing @param annotations for untyped parameters only.
Allowed types:bool
Default value:true
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer
-
All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically.
Configuration options:
tags
The tags that should be aligned.
Allowed values: a subset of['param', 'property', 'property-read', 'property-write', 'return', 'throws', 'type', 'var', 'method']
Default value:['method', 'param', 'property', 'return', 'throws', 'type', 'var']
align
Align comments
Allowed values:'left'
,'vertical'
Default value:'vertical'
Part of rule sets @PhpCsFixer @Symfony
-
PHPDoc annotation descriptions should not be a sentence.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer
-
Docblocks should have the same indentation as the documented subject.
Part of rule sets @PhpCsFixer @Symfony
-
Fixes PHPDoc inline tags.
Configuration options:
tags
The list of tags to normalize
Allowed types:array
Default value:['example', 'id', 'internal', 'inheritdoc', 'inheritdocs', 'link', 'source', 'toc', 'tutorial']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer
-
Changes doc blocks from single to multi line, or reversed. Works for class constants, properties and methods only.
Configuration options:
const
Whether const blocks should be single or multi line
Allowed values:'multi'
,'single'
,null
Default value:'multi'
property
Whether property doc blocks should be single or multi line
Allowed values:'multi'
,'single'
,null
Default value:'multi'
method
Whether method doc blocks should be single or multi line
Allowed values:'multi'
,'single'
,null
Default value:'multi'
-
@access
annotations should be omitted from PHPDoc.Part of rule sets @PhpCsFixer @Symfony
-
No alias PHPDoc tags should be used.
Configuration options:
replacements
Mapping between replaced annotations with new ones.
Allowed types:array
Default value:['property-read' => 'property', 'property-write' => 'property', 'type' => 'var', 'link' => 'see']
Part of rule sets @PhpCsFixer @Symfony
-
@return void
and@return null
annotations should be omitted from PHPDoc.Part of rule set @PhpCsFixer
-
@package
and@subpackage
annotations should be omitted from PHPDoc.Part of rule sets @PhpCsFixer @Symfony
-
Classy that does not inherit must not have
@inheritdoc
tags.Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer
-
Annotations in PHPDoc should be ordered so that
@param
annotations come first, then@throws
annotations, then@return
annotations.Part of rule set @PhpCsFixer
-
Order phpdoc tags by value.
Configuration options:
annotations
List of annotations to order, e.g. ["covers"].
Allowed values: a subset of['author', 'covers', 'coversNothing', 'dataProvider', 'depends', 'group', 'internal', 'method', 'property', 'property-read', 'property-write', 'requires', 'throws', 'uses']
Default value:['covers']
Part of rule set @PhpCsFixer
-
The type of
@return
annotations of methods returning a reference to itself must the configured one.Configuration options:
replacements
Mapping between replaced return types with new ones.
Allowed types:array
Default value:['this' => '$this', '@this' => '$this', '$self' => 'self', '@self' => 'self', '$static' => 'static', '@static' => 'static']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer
-
Scalar types should always be written in the same form.
int
notinteger
,bool
notboolean
,float
notreal
ordouble
.Configuration options:
types
A list of types to fix.
Allowed values: a subset of['boolean', 'callback', 'double', 'integer', 'real', 'str']
Default value:['boolean', 'callback', 'double', 'integer', 'real', 'str']
Part of rule sets @PhpCsFixer @Symfony
-
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.
Part of rule sets @PhpCsFixer @Symfony
phpdoc_single_line_var_spacing
Single line
@var
PHPDoc should have proper spacing.Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer
-
PHPDoc summary should end in either a full stop, exclamation mark, or question mark.
Part of rule sets @PhpCsFixer @Symfony
-
Fixes casing of PHPDoc tags.
Configuration options:
tags
List of tags to fix with their expected casing.
Allowed types:array
Default value:['inheritDoc']
-
Forces PHPDoc tags to be either regular annotations or inline.
Configuration options:
tags
The list of tags to fix
Allowed types:array
Default value:['api' => 'annotation', 'author' => 'annotation', 'copyright' => 'annotation', 'deprecated' => 'annotation', 'example' => 'annotation', 'global' => 'annotation', 'inheritDoc' => 'annotation', 'internal' => 'annotation', 'license' => 'annotation', 'method' => 'annotation', 'package' => 'annotation', 'param' => 'annotation', 'property' => 'annotation', 'return' => 'annotation', 'see' => 'annotation', 'since' => 'annotation', 'throws' => 'annotation', 'todo' => 'annotation', 'uses' => 'annotation', 'var' => 'annotation', 'version' => 'annotation']
Part of rule sets @PhpCsFixer @Symfony
-
Docblocks should only be used on structural elements.
Configuration options:
ignored_tags
List of ignored tags (matched case insensitively)
Allowed types:array
Default value:[]
Part of rule sets @PhpCsFixer @Symfony
-
EXPERIMENTAL: Takes
@param
annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.warning risky This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2]
@param
annotation is mandatory for the fixer to make changes, signatures of methods without it (no docblock, inheritdocs) will not be fixed. [3] Manual actions are required if inherited signatures are not properly documented.Configuration options:
scalar_types
Fix also scalar types; may have unexpected behaviour due to PHP bad type coercion system.
Allowed types:bool
Default value:true
Source PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer
-
EXPERIMENTAL: Takes
@var
annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4.warning risky This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2]
@var
annotation is mandatory for the fixer to make changes, signatures of properties without it (no docblock) will not be fixed. [3] Manual actions might be required for newly typed properties that are read before initialization.Configuration options:
scalar_types
Fix also scalar types; may have unexpected behaviour due to PHP bad type coercion system.
Allowed types:bool
Default value:true
Source PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer
-
EXPERIMENTAL: Takes
@return
annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.warning risky This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2]
@return
annotation is mandatory for the fixer to make changes, signatures of methods without it (no docblock, inheritdocs) will not be fixed. [3] Manual actions are required if inherited signatures are not properly documented.Configuration options:
scalar_types
Fix also scalar types; may have unexpected behaviour due to PHP bad type coercion system.
Allowed types:bool
Default value:true
Source PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer
-
PHPDoc should start and end with content, excluding the very first and last line of the docblocks.
Part of rule sets @PhpCsFixer @Symfony
phpdoc_trim_consecutive_blank_line_separation
Removes extra blank lines after summary and after description in PHPDoc.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer
-
The correct case must be used for standard PHP types in PHPDoc.
Configuration options:
groups
Type groups to fix.
Allowed values: a subset of['simple', 'alias', 'meta']
Default value:['simple', 'alias', 'meta']
Part of rule sets @PhpCsFixer @Symfony
-
Sorts PHPDoc types.
Configuration options:
sort_algorithm
The sorting algorithm to apply.
Allowed values:'alpha'
,'none'
Default value:'alpha'
null_adjustment
Forces the position of null (overrides sort_algorithm).
Allowed values:'always_first'
,'always_last'
,'none'
Default value:'always_first'
Part of rule sets @PhpCsFixer @Symfony
phpdoc_var_annotation_correct_order
@var
and@type
annotations must have type and name in the correct order.Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer
-
@var
and@type
annotations of classy properties should not contain the name.Part of rule sets @PhpCsFixer @Symfony
-
PHPUnit assertion method calls like
->assertSame(true, $foo)
should be written with dedicated method like->assertTrue($foo)
.warning risky Fixer could be risky if one is overriding PHPUnit's native methods.
Configuration options:
assertions
List of assertion methods to fix.
Allowed values: a subset of['assertSame', 'assertEquals', 'assertNotEquals', 'assertNotSame']
Default value:['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']
Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
PHPUnit assertions like
assertInternalType
,assertFileExists
, should be used overassertTrue
.warning risky Fixer could be risky if one is overriding PHPUnit's native methods.
Configuration options:
target
Target version of PHPUnit.
Allowed values:'3.0'
,'3.5'
,'5.0'
,'5.6'
,'newest'
Default value:'newest'
Part of rule sets @PHPUnit30Migration:risky @PHPUnit32Migration:risky @PHPUnit35Migration:risky @PHPUnit43Migration:risky @PHPUnit48Migration:risky @PHPUnit50Migration:risky @PHPUnit52Migration:risky @PHPUnit54Migration:risky @PHPUnit55Migration:risky @PHPUnit56Migration:risky @PHPUnit57Migration:risky @PHPUnit60Migration:risky @PHPUnit75Migration:risky @PHPUnit84Migration:risky
php_unit_dedicate_assert_internal_type
PHPUnit assertions like
assertIsArray
should be used overassertInternalType
.warning risky Risky when PHPUnit methods are overridden or when project has PHPUnit incompatibilities.
Configuration options:
target
Target version of PHPUnit.
Allowed values:'7.5'
,'newest'
Default value:'newest'
Part of rule sets @PHPUnit75Migration:risky @PHPUnit84Migration:risky
Source PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer
-
Usages of
->setExpectedException*
methods MUST be replaced by->expectException*
methods.warning risky Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
Configuration options:
target
Target version of PHPUnit.
Allowed values:'5.2'
,'5.6'
,'8.4'
,'newest'
Default value:'newest'
Part of rule sets @PHPUnit52Migration:risky @PHPUnit54Migration:risky @PHPUnit55Migration:risky @PHPUnit56Migration:risky @PHPUnit57Migration:risky @PHPUnit60Migration:risky @PHPUnit75Migration:risky @PHPUnit84Migration:risky
-
PHPUnit annotations should be a FQCNs including a root namespace.
Part of rule sets @PhpCsFixer @Symfony
-
All PHPUnit test classes should be marked as internal.
Configuration options:
types
What types of classes to mark as internal
Allowed values: a subset of['normal', 'final', 'abstract']
Default value:['normal', 'final']
Part of rule set @PhpCsFixer
-
Enforce camel (or snake) case for PHPUnit test methods, following configuration.
Configuration options:
case
Apply camel or snake case to test methods
Allowed values:'camel_case'
,'snake_case'
Default value:'camel_case'
Part of rule sets @PhpCsFixer @Symfony
-
Usages of
->getMock
and->getMockWithoutInvokingTheOriginalConstructor
methods MUST be replaced by->createMock
or->createPartialMock
methods.warning risky Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
Configuration options:
target
Target version of PHPUnit.
Allowed values:'5.4'
,'5.5'
,'newest'
Default value:'newest'
Part of rule sets @PHPUnit54Migration:risky @PHPUnit55Migration:risky @PHPUnit56Migration:risky @PHPUnit57Migration:risky @PHPUnit60Migration:risky @PHPUnit75Migration:risky @PHPUnit84Migration:risky
php_unit_mock_short_will_return
Usage of PHPUnit's mock e.g.
->will($this->returnValue(..))
must be replaced by its shorter equivalent such as->willReturn(...)
.warning risky Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\PhpUnit\PhpUnitMockShortWillReturnFixer
-
PHPUnit classes MUST be used in namespaced version, e.g.
\PHPUnit\Framework\TestCase
instead of\PHPUnit_Framework_TestCase
.PHPUnit v6 has finally fully switched to namespaces. You could start preparing the upgrade by switching from non-namespaced TestCase to namespaced one. Forward compatibility layer (
\PHPUnit\Framework\TestCase
class) was backported to PHPUnit v4.8.35 and PHPUnit v5.4.0. Extended forward compatibility layer (PHPUnit\Framework\Assert
,PHPUnit\Framework\BaseTestListener
,PHPUnit\Framework\TestListener
classes) was introduced in v5.7.0.warning risky Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
Configuration options:
target
Target version of PHPUnit.
Allowed values:'4.8'
,'5.7'
,'6.0'
,'newest'
Default value:'newest'
Part of rule sets @PHPUnit48Migration:risky @PHPUnit50Migration:risky @PHPUnit52Migration:risky @PHPUnit54Migration:risky @PHPUnit55Migration:risky @PHPUnit56Migration:risky @PHPUnit57Migration:risky @PHPUnit60Migration:risky @PHPUnit75Migration:risky @PHPUnit84Migration:risky
php_unit_no_expectation_annotation
Usages of
@expectedException*
annotations MUST be replaced by->setExpectedException*
methods.warning risky Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.
Configuration options:
target
Target version of PHPUnit.
Allowed values:'3.2'
,'4.3'
,'newest'
Default value:'newest'
use_class_const
Use ::class notation.
Allowed types:bool
Default value:true
Part of rule sets @PHPUnit32Migration:risky @PHPUnit35Migration:risky @PHPUnit43Migration:risky @PHPUnit48Migration:risky @PHPUnit50Migration:risky @PHPUnit52Migration:risky @PHPUnit54Migration:risky @PHPUnit55Migration:risky @PHPUnit56Migration:risky @PHPUnit57Migration:risky @PHPUnit60Migration:risky @PHPUnit75Migration:risky @PHPUnit84Migration:risky
Source PhpCsFixer\Fixer\PhpUnit\PhpUnitNoExpectationAnnotationFixer
php_unit_set_up_tear_down_visibility
Changes the visibility of the
setUp()
andtearDown()
functions of PHPUnit toprotected
, to match the PHPUnit TestCase.warning risky This fixer may change functions named
setUp()
ortearDown()
outside of PHPUnit tests, when a class is wrongly seen as a PHPUnit test.Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\PhpUnit\PhpUnitSetUpTearDownVisibilityFixer
-
All PHPUnit test cases should have
@small
,@medium
or@large
annotation to enable run time limits.The special groups [small, medium, large] provides a way to identify tests that are taking long to be executed.
Configuration options:
group
Define a specific group to be used in case no group is already in use
Allowed values:'large'
,'medium'
,'small'
Default value:'small'
-
PHPUnit methods like
assertSame
should be used instead ofassertEquals
.warning risky Risky when any of the functions are overridden or when testing object equality.
Configuration options:
assertions
List of assertion methods to fix.
Allowed values: a subset of['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']
Default value:['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']
Part of rule set @PhpCsFixer:risky
-
Adds or removes @test annotations from tests, following configuration.
warning risky This fixer may change the name of your tests, and could cause incompatibility with abstract classes or interfaces.
Configuration options:
style
Whether to use the @test annotation or not.
Allowed values:'annotation'
,'prefix'
Default value:'prefix'
Part of rule sets @PhpCsFixer:risky @Symfony:risky
php_unit_test_case_static_method_calls
Calls to
PHPUnit\Framework\TestCase
static methods must all be of the same type, either$this->
,self::
orstatic::
.warning risky Risky when PHPUnit methods are overridden or not accessible, or when project has PHPUnit incompatibilities.
Configuration options:
call_type
The call type to use for referring to PHPUnit methods.
Allowed values:'self'
,'static'
,'this'
Default value:'static'
methods
Dictionary of method => call_type values that differ from the default strategy.
Allowed types:array
Default value:[]
Part of rule set @PhpCsFixer:risky
Source PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer
php_unit_test_class_requires_covers
Adds a default
@coversNothing
annotation to PHPUnit test classes that have no@covers*
annotation.Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\PhpUnit\PhpUnitTestClassRequiresCoversFixer
-
Converts
pow
to the**
operator.warning risky Risky when the function
pow
is overridden.Part of rule sets @PHP56Migration:risky @PHP70Migration:risky @PHP71Migration:risky @PHP74Migration:risky @PHP80Migration:risky @PhpCsFixer:risky @Symfony:risky
-
Converts
protected
variables and methods toprivate
where possible.Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\ProtectedToPrivateFixer
-
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.
warning risky This fixer may change your class name, which will break the code that depends on the old name.
Configuration options:
dir
If provided, the directory where the project code is placed.
Allowed types:null
,string
Default value:null
Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Replaces
rand
,srand
,getrandmax
functions calls with theirmt_*
analogs orrandom_int
.warning risky Risky when the configured functions are overridden. Or when relying on the seed based generating of the numbers.
Configuration options:
replacements
Mapping between replaced functions with the new ones.
Allowed types:array
Default value:['getrandmax' => 'mt_getrandmax', 'rand' => 'mt_rand', 'srand' => 'mt_srand']
Part of rule sets @PHP70Migration:risky @PHP71Migration:risky @PHP74Migration:risky @PHP80Migration:risky
-
Callables must be called without using
call_user_func*
when possible.warning risky Risky when the
call_user_func
orcall_user_func_array
function is overridden or when are used in constructions that should be avoided, likecall_user_func_array('foo', ['bar' => 'baz'])
orcall_user_func($foo, $foo = 'bar')
.Source PhpCsFixer\Fixer\FunctionNotation\RegularCallableCallFixer
-
Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method.
Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\ReturnNotation\ReturnAssignmentFixer
-
There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
Rule is applied only in a PHP 7+ environment.
Configuration options:
space_before
Spacing to apply before colon.
Allowed values:'none'
,'one'
Default value:'none'
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer
-
Inside class or interface element
self
should be preferred to the class name itself.warning risky Risky when using dynamic calls like get_called_class() or late static binding.
Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Inside a
final
class or anonymous classself
should be preferred tostatic
.Source PhpCsFixer\Fixer\ClassNotation\SelfStaticAccessorFixer
-
Instructions must be terminated with a semicolon.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer
-
Cast shall be used, not
settype
.warning risky Risky when the
settype
function is overridden or when used as the 2nd or 3rd expression in afor
loop .Part of rule sets @PhpCsFixer:risky @Symfony:risky
-
Cast
(boolean)
and(integer)
should be written as(bool)
and(int)
,(double)
and(real)
as(float)
,(binary)
as(string)
.Part of rule sets @PHP74Migration @PHP80Migration @PHP81Migration @PSR12 @PhpCsFixer @Symfony
simple_to_complex_string_variable
Converts explicit variables in double-quoted strings and heredoc syntax from simple to complex format (
${
to{$
).Doesn't touch implicit variables. Works together nicely with
explicit_string_variable
.Part of rule set @PhpCsFixer
Source PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer
-
Simplify
if
control structures that return the boolean result of their condition.Source PhpCsFixer\Fixer\ControlStructure\SimplifiedIfReturnFixer
-
A return statement wishing to return
void
should not returnnull
.Source PhpCsFixer\Fixer\ReturnNotation\SimplifiedNullReturnFixer
-
A PHP file without end tag must always end with a single empty line feed.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer
single_blank_line_before_namespace
There should be exactly one blank line before a namespace declaration.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer
single_class_element_per_statement
There MUST NOT be more than one property or constant declared per statement.
Configuration options:
elements
List of strings which element should be modified.
Allowed values: a subset of['const', 'property']
Default value:['const', 'property']
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer
-
There MUST be one use keyword per declaration.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer
-
Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
-
Single-line comments and multi-line comments with only one line of actual content should use the
//
syntax.Configuration options:
comment_types
List of comment types to fix
Allowed values: a subset of['asterisk', 'hash']
Default value:['asterisk', 'hash']
Part of rule sets @PhpCsFixer @Symfony
-
Throwing exception must be done in single line.
Part of rule set @Symfony
Source PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer
-
Convert double quotes to single quotes for simple strings.
Configuration options:
strings_containing_single_quote_chars
Whether to fix double-quoted strings that contains single-quotes.
Allowed types:bool
Default value:false
Part of rule sets @PhpCsFixer @Symfony
-
Ensures a single space after language constructs.
Configuration options:
constructs
List of constructs which must be followed by a single space.
Allowed values: a subset of['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'enum', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']
Default value:['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'enum', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAfterConstructFixer
single_trait_insert_per_statement
Each trait
use
must be done as single statement.Part of rule sets @PSR12 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer
-
Fix whitespace after a semicolon.
Configuration options:
remove_in_empty_for_expressions
Whether spaces should be removed for empty for expressions.
Allowed types:bool
Default value:false
Part of rule sets @PhpCsFixer @Symfony
-
Increment and decrement operators should be used if possible.
Part of rule sets @PhpCsFixer @Symfony
-
Replace all
<>
with!=
.Part of rule sets @PhpCsFixer @Symfony
-
Lambdas not (indirect) referencing
$this
must be declaredstatic
.warning risky Risky when using
->bindTo
on lambdas without referencing to$this
. -
Comparisons should be strict.
warning risky Changing comparisons to strict might change code behavior.
Part of rule set @PhpCsFixer:risky
-
Functions should be used with
$strict
param set totrue
.The functions "array_keys", "array_search", "base64_decode", "in_array" and "mb_detect_encoding" should be used with $strict param.
warning risky Risky when the fixed function is overridden or if the code relies on non-strict usage.
Part of rule set @PhpCsFixer:risky
-
String tests for empty must be done against
''
, not withstrlen
.warning risky Risky when
strlen
is overridden, when called using astringable
object, also no longer triggers warning when called using non-string(able).Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\StringNotation\StringLengthToEmptyFixer
-
All multi-line strings must use correct line ending.
warning risky Changing the line endings of multi-line strings might affect string comparisons and outputs.
Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\StringNotation\StringLineEndingFixer
switch_case_semicolon_to_colon
A case should be followed by a colon and not a semicolon.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\SwitchCaseSemicolonToColonFixer
-
Removes extra spaces between colon and case value.
Part of rule sets @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\SwitchCaseSpaceFixer
-
Switch case must not be ended with
continue
but withbreak
.Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\SwitchContinueToBreakFixer
-
Standardize spaces around ternary operator.
Part of rule sets @PSR12 @PhpCsFixer @Symfony
-
Use the Elvis operator
?:
where possible.warning risky Risky when relying on functions called on both sides of the
?
operator.Part of rule sets @PhpCsFixer:risky @Symfony:risky
Source PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer
-
Use
null
coalescing operator??
where possible. Requires PHP >= 7.0.Part of rule sets @PHP70Migration @PHP71Migration @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration
Source PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer
-
Multi-line arrays, arguments list and parameters list must have a trailing comma.
Configuration options:
after_heredoc
Whether a trailing comma should also be placed after heredoc end.
Allowed types:bool
Default value:false
elements
Where to fix multiline trailing comma (PHP >= 7.3 required for arguments, PHP >= 8.0 for parameters).
Allowed values: a subset of['arrays', 'arguments', 'parameters']
Default value:['arrays']
Part of rule sets @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer
-
Arrays should be formatted like function/method arguments, without leading or trailing single line space.
Part of rule sets @PhpCsFixer @Symfony
-
A single space or none should be around union type operator.
Configuration options:
space
spacing to apply around union type operator.
Allowed values:'none'
,'single'
Default value:'none'
Part of rule sets @PhpCsFixer @Symfony
-
Unary operators should be placed adjacent to their operands.
Part of rule sets @PhpCsFixer @Symfony
-
Anonymous functions with one-liner return statement must use arrow functions.
warning risky Risky when using
isset()
on outside variables that are not imported withuse ()
.Part of rule sets @PHP74Migration:risky @PHP80Migration:risky
Source PhpCsFixer\Fixer\FunctionNotation\UseArrowFunctionsFixer
-
Visibility MUST be declared on all properties and methods;
abstract
andfinal
MUST be declared before the visibility;static
MUST be declared after the visibility.Configuration options:
elements
The structural elements to fix (PHP >= 7.1 required for const).
Allowed values: a subset of['property', 'method', 'const']
Default value:['property', 'method', 'const']
Part of rule sets @PHP71Migration @PHP73Migration @PHP74Migration @PHP80Migration @PHP81Migration @PSR12 @PSR2 @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer
-
Add
void
return type to functions with missing or empty return statements, but priority is given to@return
annotations. Requires PHP >= 7.1.warning risky Modifies the signature of functions.
Part of rule sets @PHP71Migration:risky @PHP74Migration:risky @PHP80Migration:risky
whitespace_after_comma_in_array
In array declaration, there MUST be a whitespace after each comma.
Part of rule sets @PhpCsFixer @Symfony
Source PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer
-
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.Configuration options:
equal
Style for equal (==, !=) statements.
Allowed types:bool
,null
Default value:true
identical
Style for identical (===, !==) statements.
Allowed types:bool
,null
Default value:true
less_and_greater
Style for less and greater than (<, <=, >, >=) statements.
Allowed types:bool
,null
Default value:null
always_move_variable
Whether variables should always be on non assignable side when applying Yoda style.
Allowed types:bool
Default value:false
Part of rule sets @PhpCsFixer @Symfony