Back to Php Cs Fixer

UPGRADE GUIDE FROM 2.x to 3.0

UPGRADE-v3.md

3.95.117.4 KB
Original Source

UPGRADE GUIDE FROM 2.x to 3.0

This is guide for upgrade from version 2.x to 3.0 for using the CLI tool.

Before following this guide, install v2.19 and run in verbose mode (php-cs-fixer fix -v) or in future mode (PHP_CS_FIXER_FUTURE_MODE=1 php-cs-fixer fix) to identify deprecations and fix them first.

Rename of files

2.x3.0Description
.php_cs.php-cs-fixer.phpConfiguration file (local)
.php_cs.dist.php-cs-fixer.dist.phpConfiguration file (to be distributed)
.php_cs.cache.php-cs-fixer.cacheCache file

CLI options

2.x3.0DescriptionNote
--diff-formatType of differOption was removed, all diffs are now
udiff
--show-progress--show-progressType of progress indicatorAllowed values were modified:
run-in and estimating was removed,
estimating-max was renamed to dots
--rules--rulesDefault value changed from @PSR2 to @PSR12
--config --rulesNo longer allowed to pass both

Changes to rules

Renamed rules

Old nameNew nameNote
blank_line_before_returnblank_line_before_statementuse configuration ['statements' => ['return']]
final_static_accessself_static_accessor
hash_to_slash_commentsingle_line_comment_styleuse configuration ['comment_types' => ['hash']]
lowercase_constantsconstant_caseuse configuration ['case' => 'lower']
method_separationclass_attributes_separationuse configuration ['elements' => ['method']]
no_extra_consecutive_blank_linesno_extra_blank_lines
no_multiline_whitespace_before_semicolonsmultiline_whitespace_before_semicolons
no_short_echo_tagecho_tag_syntaxuse configuration ['format' => 'long']
php_unit_ordered_coversphpdoc_order_by_valueuse configuration ['annotations' => [ 'covers' ]]
phpdoc_inline_taggeneral_phpdoc_tag_rename, phpdoc_inline_tag_normalizer and phpdoc_tag_type
pre_incrementincrement_styleuse configuration ['style' => 'pre']
psr0psr_autoloadinguse configuration ['dir' => x ]
psr4psr_autoloading
silenced_deprecation_errorerror_suppression
trailing_comma_in_multiline_arraytrailing_comma_in_multilineuse configuration ['elements' => ['arrays']]

Removed rootless configuration

RuleRoot optionNote
general_phpdoc_annotation_removeannotations
no_extra_consecutive_blank_linestokens
no_spaces_around_offsetpositions
no_unneeded_control_parenthesesstatements
ordered_class_elementsorder
php_unit_constructassertions
php_unit_dedicate_asserttargetroot option works differently than rootless configuration
php_unit_strictassertions
phpdoc_no_alias_tagreplacements
phpdoc_return_self_referencereplacements
random_api_migrationreplacements
single_class_element_per_statementelements
visibility_requiredelements

Changed options

RuleOptionChange
binary_operator_spacesalign_double_arrowoption was removed, use operators instead
binary_operator_spacesalign_equalsoption was removed use operators instead
blank_line_before_statementstatements: dieoption die was removed from statements, use exit instead
class_attributes_separationelementsoption does no longer accept flat array as a value, use map instead
class_definitionmultiLineExtendsEachSingleLineoption was renamed to multi_line_extends_each_single_line
class_definitionsingleItemSingleLineoption was renamed to single_item_single_line
class_definitionsingleLineoption was renamed to single_line
doctrine_annotation_spacesaround_argument_assignmentsoption was removed, use before_argument_assignments and after_argument_assignments instead
doctrine_annotation_spacesaround_array_assignmentsoption was removed, use after_array_assignments_colon, after_array_assignments_equals, before_array_assignments_colon and before_array_assignments_equals instead
final_internal_classannotation-black-listoption was renamed, use annotation_exclude
final_internal_classannotation-white-listoption was renamed, use annotation_include
final_internal_classconsider-absent-docblock-as-internal-classoption was renamed, use consider_absent_docblock_as_internal_class
header_commentcommentTypeoption was renamed to comment_type
is_nulluse_yoda_styleoption was removed, use yoda_style rule instead
no_extra_consecutive_blank_linestokensone of possible values, useTrait, was renamed to use_trait
ordered_class_elementssortAlgorithmoption was renamed, use sort_algorithm instead
ordered_importsimportsOrderoption was renamed, use imports_order
ordered_importssortAlgorithmoption was renamed, use sort_algorithm
php_unit_dedicate_assertfunctionsoption was removed, use target instead
php_unit_test_annotationcaseoption was removed, use php_unit_method_casing rule instead

Changed default values of options

RuleOptionOld valueNew value
array_syntaxsyntax'long''short'
function_to_constantfunctions['get_class', 'php_sapi_name', 'phpversion', 'pi']['get_called_class', 'get_class', 'php_sapi_name', 'phpversion', 'pi']
list_syntaxsyntax'long''short'
method_argument_spaceon_multiline'ignore''ensure_fully_multiline'
native_constant_invocationstrictfalsetrue
native_function_casinginclude'@internal''@compiler_optimized'
native_function_invocationinclude'@internal''@compiler_optimized'
native_function_invocationstrictfalsetrue
non_printable_characteruse_escape_sequences_in_stringsfalsetrue (when running on PHP 7.0 and up)
php_unit_dedicate_asserttarget'5.0''newest'
phpdoc_aligntags['param', 'return', 'throws', 'type', 'var']['method', 'param', 'property', 'return', 'throws', 'type', 'var']
phpdoc_scalartypes['boolean', 'double', 'integer', 'real', 'str']['boolean', 'callback', 'double', 'integer', 'real', 'str']

Removed rule sets

Rule setNote
@PHP56Migrationwas empty

Rule behaviour changes

  • no_unused_imports now runs all files defined in the configuration (used to exclude some hardcoded directories)

Various

  • udiff output now includes the file name in the output (if applicable)

Code BC changes

Removed; various

  • class AbstractAlignFixerHelper has been removed
  • class AccessibleObject has been removed
  • class AlignDoubleArrowFixerHelper has been removed
  • class AlignEqualsFixerHelper has been removed
  • class FixerConfigurationResolverRootless has been removed
  • HeaderCommentFixer deprecated properties have been removed
  • MethodArgumentSpaceFixer deprecated methods have been removed
  • NoMixedEchoPrintFixer the property $defaultConfig has been removed
  • class Tokens, the following methods has been removed:
    • current()
    • key()
    • next()
    • rewind()
    • valid()
  • namespace PhpCsFixer\Test\ and each class in it has been removed, as it served pure development purpose and should not be part of production code - reach out to community if you are willing to help building dev package

Interface changes

  • ConfigurableFixerInterface has been updated
  • ConfigurationDefinitionFixerInterface has been removed in favour of the updated ConfigurableFixerInterface
  • DefinedFixerInterface has been removed, related methods are now part of the updated FixerInterface interface
  • DifferInterface has been updated
  • FixerInterface interface has been updated
  • PhpCsFixer\RuleSetInterface has been removed in favour of \PhpCsFixer\RuleSet\RuleSetInterface

BC breaks; various

BC breaks; common internal classes

  • method getClassyElements of class TokensAnalyzer parameter $returnTraitsImports has been removed; now always returns trait import information
  • method getSetDefinitionNames of class RuleSet has been removed, use RuleSets::getSetDefinitionNames()