Skip to content

Instantly share code, notes, and snippets.

@0hsn
Last active April 5, 2022 23:25
Show Gist options
  • Save 0hsn/e70ae0c30d10a2657b33e04e3072683f to your computer and use it in GitHub Desktop.
Save 0hsn/e70ae0c30d10a2657b33e04e3072683f to your computer and use it in GitHub Desktop.
PHP-CS-Fixer v3.x migration guide for custom configuration
<?php
$config = new \PhpCsFixer\Config();
$config->setRules([
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'multiline_whitespace_before_semicolons' => true,
'single_quote' => true,
'binary_operator_spaces' => [],
'braces' => [
'allow_single_line_closure' => true,
],
'concat_space' => ['spacing' => 'none'],
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'include' => true,
'lowercase_cast' => true,
'no_extra_blank_lines' => [
'tokens' => [
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'square_brace_block',
'throw',
'use',
],
],
'no_multiline_whitespace_around_double_arrow' => true,
'no_spaces_around_offset' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
'phpdoc_order' => false,
'phpdoc_summary' => true,
'return_type_declaration' => ['space_before' => 'one'],
'single_blank_line_before_namespace' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'function_declaration' => true,
'indentation_type' => true,
'no_spaces_after_function_name' => true,
'no_spaces_inside_parenthesis' => true,
'not_operator_with_successor_space' => true,
])
->setLineEnding("\n")
->setUsingCache(false);
return $config;

Recently (27/07/2021) I have updated my PHP-CS-Fixer to 3.x. I found out there are a lot of things updated from 2.x to 3.x. This gist is about the new configuration file I made, following the migration guide.

Basically, I ran this command PHP_CS_FIXER_FUTURE_MODE=1 php-cs-fixer fix, and fixed the issues given on console.

I used to use a custom .php_cs configuration from zaratedev/.php_cs. I had to rename the file from .php_cs to .php-cs-fixer.php as a cricial change mentioned on migration guide.

Useful links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment