rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.69k stars 684 forks source link

CountOnNullRector: two counts on the same type, different results #992

Closed jkuchar closed 5 years ago

jkuchar commented 5 years ago

is wrongly corrected like this:

Rector dev-master@f12d320 dibi: dev-master@19172c801e0773433fd4fed062b536944766bd38

<?php declare(strict_types=1);

$fn = function() {

    $primaryColumns = dibi::getDatabaseInfo()->getTable($this->table)->getPrimaryKey()->getColumns(); // returns an array

    if (count($primaryColumns) === 0) {
        throw new Exception("x");
    }

-   if (count($primaryColumns) > 1) {
+   if ((is_array($primaryColumns) || $primaryColumns instanceof \Countable ? count($primaryColumns) : 0) > 1) {
        throw new Exception("y");
    }

    return $primaryColumns[0]->getName();

};
TomasVotruba commented 5 years ago

Indeed. Thanks for reporting