Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Okay, I know php-cs-fixer allows following levels of fixes for coding standards:

php php-cs-fixer.phar fix /path/to/project --level=psr0
php php-cs-fixer.phar fix /path/to/project --level=psr1
php php-cs-fixer.phar fix /path/to/project --level=psr2
php php-cs-fixer.phar fix /path/to/project --level=symfony 

I know that psr0, psr1, psr2 levels maintain specified coding standards.

But I want to know what --level=symfony offers and how does that coding standard differ from psr2.

Also if we don't the provide the --level option at all. Does is assume --level=psr2 by default?

like image 748
kabirbaidhya Avatar asked Apr 24 '15 05:04

kabirbaidhya


2 Answers

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.

like image 121
Tomas Votruba Avatar answered Sep 24 '22 22:09

Tomas Votruba


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.
like image 37
Sergei Gorjunov Avatar answered Sep 23 '22 22:09

Sergei Gorjunov