Php-cs-fixer: Bug in NoSuperfluousPhpdocTags

Created on 11 Apr 2020  路  6Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using ($ php -v):

=> 7.4 (running on github actions)

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> v2.16.2 Yellow Bird

The command you use to run PHP CS Fixer:

=> php-cs-fixer fix

The configuration file you are using, if any:

<?php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__.'/src')
    ->in(__DIR__.'/tests')
;

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules([
        '@PSR2' => true,
        '@Symfony' => true,
        'array_syntax' => ['syntax' => 'short'],
        'blank_line_after_opening_tag' => true,
        'concat_space' => ['spacing' => 'one'],
        'declare_strict_types' => false,
        'fully_qualified_strict_types' => true,
        'header_comment' => false,
        'lowercase_cast' => true,
        'is_null' => true,
        'magic_method_casing' => true,
        'modernize_types_casting' => true,
        'multiline_comment_opening_closing' => true,
        'native_constant_invocation' => true,
        'no_alias_functions' => true,
        'no_alternative_syntax' => true,
        'no_blank_lines_after_phpdoc' => true,
        'no_empty_comment' => true,
        'no_empty_phpdoc' => true,
        'no_extra_blank_lines' => true,
        'no_leading_import_slash' => true,
        'no_spaces_around_offset' => true,
        'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
        'no_trailing_comma_in_singleline_array' => true,
        'no_unset_cast' => true,
        'no_unused_imports' => true,
        'no_useless_else' => true,
        'no_useless_return' => true,
        'no_whitespace_in_blank_line' => true,
        'ordered_imports' => true,
        'ordered_interfaces' => true,
        'php_unit_mock' => ['target' => 'newest'],
        'php_unit_dedicate_assert_internal_type' => ['target' => 'newest'],
        'php_unit_expectation' => ['target' => 'newest'],
        'php_unit_no_expectation_annotation' => ['target' => 'newest'],
        // 'php_unit_test_annotation' => ['style' => 'prefix'],
        'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
        'php_unit_mock_short_will_return' => true,
        'phpdoc_align' => ['align' => 'vertical'],
        'phpdoc_line_span' => ['method' => 'multi', 'property' => 'multi'],
        'phpdoc_scalar' => true,
        'phpdoc_separation' => true,
        'phpdoc_single_line_var_spacing' => true,
        'phpdoc_trim' => true,
        'phpdoc_trim_consecutive_blank_line_separation' => true,
        'phpdoc_types' => true,
        'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
        'phpdoc_var_without_name' => true,
        'short_scalar_cast' => true,
        'single_line_throw' => true,
        'single_trait_insert_per_statement' => true,
        'standardize_not_equals' => true,
        'visibility_required' => true,
        'yoda_style' => true,
        'native_function_invocation' => ['include' => ['@compiler_optimized']],
        'compact_nullable_typehint' => true,
        'declare_equal_normalize' => ['space' => 'none'],
        'function_typehint_space' => true,
        'no_leading_namespace_whitespace' => true,
        'blank_line_before_statement' => true,
        'single_quote' => true,
        'phpdoc_to_comment' => false,
        'ordered_class_elements' => ['sortAlgorithm'=>'none'],
        'class_attributes_separation' => ['elements'=>['property', 'method']],
        'array_indentation' => true,
    ])
    ->setFinder($finder)
;

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
class MyEnum {
  const ONE=1;
  const TWO=2;
}

class Foo {
    /**
     * @var null|MyEnum::*
     */ 
    private $numbers;

    /**
     * @var list<MyEnum::*> 
     */ 
    private $numbers;
}

This is supported by PSALM: https://psalm.dev/docs/annotating_code/typing_in_psalm/#specifying-stringint-options-aka-enums

I dont expect these comments to be removed. Version v2.16.1 did not remove them. Version v2.16.1 does remove these comments.

kinbug

All 6 comments

Mmh not really a bug: we don't support Psalm specific syntaxes. This should be fixed with #4914.

Yeah, Hm. Sure, you can label it a feature because it has never been an intent to support it.

I would claim it it a bug since it is a side-effect of a patch release. Using version 2.16.2 will break my code.

Thank you for the PR. I'll review it and answer your questions.

Actually I investigated a bit more and found the real bug, see #4915 :)

The same issue happens with phpstan syntax:

    /**
     * @var class-string<Enum>
     */
    protected $enumeration;

which gets removed in 2.16.2

Closing as #4915 was merged.

Thank you @juliendufresne

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fisharebest picture fisharebest  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

Bilge picture Bilge  路  3Comments

grachevko picture grachevko  路  3Comments