Skip to content

[PHP] CountOnNull on properties with PHPDoc shouldn't apply #2474

@gnutix

Description

@gnutix

I've had the case in my code base that the following code change was triggered :

/** @var string[] $array */
$array = $someObject->someMethod();

- if (count($array) > 0) {
+ if (is_countable($array) ? count($array) > 0 : 0) {

}

I was quite surprised by this proposition, as IMO a string[] doesn't need to be surrounded by is_countable (if the developer is misusing type hints/doc blocks, PHPStan should warn him).

I digged into it and even noticed there's a test Fixture that seems to affirm this behavior :

packages/Php71/tests/Rector/FuncCall/CountOnNullRector/Fixture/property_with_doc.php.inc

Isn't that weird ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions