rectorphp / rector

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

Unexpected item 'parameters › checkAlwaysTrueLooseComparison' #7141

Closed internalsystemerror closed 2 years ago

internalsystemerror commented 2 years ago

Bug Report

Subject Details
Rector version 0.12.22

Minimal PHP Code Causing Issue

I'm not able to reproduce this using the demo, however this is extremely similar to https://github.com/rectorphp/rector/issues/7133 and appears to be caused by phpstan/phpstan-strict-rules. The specific error:

PHP Fatal error:  Uncaught _PHPStan_c0c409264\Nette\Schema\ValidationException: Unexpected item 'parameters › checkAlwaysTrueLooseComparison', did you mean 'checkAlwaysTrueStrictComparison'? in phar:///home/ise/projects/creativecow/stratum-monorepo-php/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/schema/src/Schema/Processor.php:75

I will update this as I investigate to try and get further information. The only place I can find checkAlwaysTrueLooseComparison is in the file rules.neon in the strict-rules package.

This was introduced in https://github.com/phpstan/phpstan-strict-rules/commit/f3ca6464eae640a556c69a02b3b77a2507475d2f and released in v1.2.1. Rolling back to v1.2.0 fixes the issue.

Expected Behaviour

No error

samsonasik commented 2 years ago

it seems phpstan.phar from vendor is read early before autoload, it possibly solvable by flip autoload in bin/rector.php:

https://github.com/rectorphp/rector/blob/0e76f19491498c136b698dc22b9b30d44a4e832c/bin/rector.php#L31-L32

into:

$autoloadIncluder->autoloadProjectAutoloaderFile();
$autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/scoper-autoload.php');

@internalsystemerror could you verify if that solve it?

internalsystemerror commented 2 years ago

@internalsystemerror could you verify if that solve it?

@samsonasik Sadly not, same error.

samsonasik commented 2 years ago

Could you create sample repository for it? it may happen again when new parameter config added to next patch phpstan version so it should be solved by modify the use of autoload, or mark phpstan in scoped vendor as replaced via composer replace:

  "replace": {
        "phpstan/phpstan": "*"
    }

before build scoped.

internalsystemerror commented 2 years ago

I'm currently experiencing a tight approaching deadline, and we run rector against our entire monorepo so it would take me some time to figure out an exact reproduction. Forcing "phpstan/phpstan-strict-rules": "1.2.0" works for now until I can look at this again.

I did try a combination of ordering of those lines in bin/rector.php but nothing seemed to resolve the issue.

samsonasik commented 2 years ago

@internalsystemerror please try latest dev-main for now as its phpstan vendor is now re-generated to latest phpstan:

composer config minimum-stability dev
composer config prefer-stable true
composer require --dev rector/rector:dev-main
internalsystemerror commented 2 years ago

Yep, that appears to have fixed it, thank you! As to how to solve it more permanently however, I would be interested in looking into this further, but work permitting.

samsonasik commented 2 years ago

The vendor prefixed seems include phpstan bootstrap from existing vendor itself: https://github.com/rectorphp/rector/blob/af9fe53cfa3c6f98c33ad47cbb0994f05ed2ef59/vendor/composer/autoload_files.php#L17

jordisala1991 commented 2 years ago

Saw same error on Sonata. I am also interested on a more permanent solution (I know it will be fixed on 0.12.23). My plan is to keep integrating rector on all Sonata repositories

If I understand correctly, this comes from the fact that rector ships its own vendor folder with phpstan installed on it, but that phpstan still looks for the phpstan configuration of the outside vendors, right?

samsonasik commented 2 years ago

Rector 0.12.23 released. I am closing it, if the new phpstan patch add new parameter again in the future, it may need a new release or use dev-main in the meantime if the phpstan prefixed vendor is still loaded first.