php-cs-fixer: need more information on using fix --level option php-cs-fixer: need more information on using fix --level option php php

php-cs-fixer: need more information on using fix --level option


Now in 2017, since version 2, you can use describe command.

vendor/bin/php-cs-fixer describe @PSR2

It shows you current fixers in the ruleset with names and description:

enter image description here

So for "Symfony" ruleset it would look like:

vendor/bin/php-cs-fixer describe @Symfony

And for single rule like:

vendor/bin/php-cs-fixer describe some_rule

Level changed to @Rule

Also notice level option was deprecated. Use it as rule, just with @ prefix instead.

vendor/bin/php-cs-fixer --rules=@PSR2

If you look for more details, see related PR.


As I see from this document https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/1.8/README.rst it executes this list of filters:

  • blankline_after_open_tag - Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
  • concat_without_spaces - Concatenation should be used without spaces.
  • double_arrow_multiline_whitespaces - Operator => should not be arounded by multi-line whitespaces.
  • duplicate_semicolon - Remove duplicated semicolons.
  • empty_return - A return statement wishing to return nothing should be simply "return".
  • extra_empty_lines - Removes extra empty lines.
  • include - Include and file path should be divided with a single space. File path should not be placed under brackets.
  • join_function - Implode function should be used instead of join function.
  • list_commas - Remove trailing commas in list function calls.
  • multiline_array_trailing_comma - PHP multi-line arrays should have a trailing comma.
  • namespace_no_leading_whitespace - The namespace declaration line shouldn't contain leading whitespace.
  • new_with_braces - All instances created with new keyword must be followed by braces.
  • no_blank_lines_after_class_opening - There should be no empty lines after class opening brace.
  • no_empty_lines_after_phpdocs - There should not be blank lines between docblock and the documented element.
  • object_operator - There should not be space before or after object T_OBJECT_OPERATOR.
  • operators_spaces - Binary operators should be arounded by at least one space.
  • phpdoc_indent - Docblocks should have the same indentation as the documented subject.
  • phpdoc_no_access - @access annotations should be omitted from phpdocs.
  • phpdoc_no_empty_return - @return void and @return null annotations should be omitted from phpdocs.
  • phpdoc_no_package - @package and @subpackage annotations should be omitted from phpdocs.
  • phpdoc_params - All items of the @param, @throws, @return, @var, and @type phpdoc tags must be aligned vertically.
  • phpdoc_scalar - Scalar types should always be written in the same form. "int", not "integer"; "bool", not "boolean"; "float", not "real" or "double".
  • phpdoc_separation - Annotations in phpdocs 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_short_description - Phpdocs short descriptions should end in either a full stop, exclamation mark, or question mark.
  • phpdoc_to_comment - Docblocks should only be used on structural elements.
  • phpdoc_trim - Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
  • phpdoc_type_to_var - @type should always be written as @var.
  • phpdoc_var_without_name - @var and @type annotations should not contain the variable name.
  • remove_leading_slash_use - Remove leading slashes in use clauses.
  • remove_lines_between_uses - Removes line breaks between use statements.
  • return - An empty line feed should precede a return statement.
  • self_accessor - Inside a classy element "self" should be preferred to the class name itself.
  • single_array_no_trailing_comma - PHP single-line arrays should not have trailing comma.
  • single_blank_line_before_namespace - There should be exactly one blank line before a namespace declaration.
  • single_quote - Convert double quotes to single quotes for simple strings.
  • spaces_before_semicolon - Single-line whitespace before closing semicolon are
  • spaces_cast - A single space should be between cast and variable.
  • standardize_not_equal - Replace all <> with !=.
  • ternary_spaces - Standardize spaces around ternary operator.
  • trim_array_spaces - Arrays should be formatted like function/method arguments, without leading or trailing single line space.
  • unalign_double_arrow - Unalign double arrow symbols.
  • unalign_equals - Unalign equals symbols.
  • unary_operators_spaces - Unary operators should be placed adjacent to their operands.
  • unused_use - Unused use statements must be removed.
  • whitespacy_lines - Remove trailing whitespace at the end of blank lines.


Here's a good blog post on using php-cs-fixer and here it implies that by default it uses psr2 fixers if the --level option is not provided.

But, if we pass --level=symfony explicitly it runs some “additional” checks, which are targeted at Symfony and go above-and-beyond PSR2

By default, it runs “all PSR-2 fixers and some additional ones.” You can toggle the level you want to run with the --level flag, which I’ll be setting to psr2 so that the “additional” checks, which are targeted at Symfony and go above-and-beyond PSR2, don’t throw me off. (It runs the entire stack by default, which is called level “symfony” and includes things like “Align equals signs in subsequent lines”).

Also the php-cs-fixer README on github provides some information about the filters that are run in PSR-0, PSR-1, PSR-2 and symfony.