For some reason rector seems to load Doctrine\Common\Cache\RiakCache from my local project, and then also from the global ~/.config/composer directory where I installed rector (and it's dependencies), because its requirements clashed with older libraries in my project.
| Subject | Details |
| :------------- | :----------------------------------------------------------- |
| PHP version | PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS ) |
| Full Command | ~/.config/composer/vendor/bin/rector process . --set laravel56 --debug |
[parsing] /mnt/c/Users/hjpol/[..my project..]/vendor/doctrine/cache/lib/Doctrine/Common/Cache/RiakCache.php
PHP Fatal error: Cannot use Riak\Object as Object because 'Object' is a special class name in /home/henk/.config/composer/vendor/doctrine/cache/lib/Doctrine/Common/Cache/RiakCache.php on line 8
https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/RiakCache.php
There is not much we can do, as 3rd party code is broken by using reserved PHP Object word.
What minimal PHP code your run Rector on is causing this?
@TomasVotruba @HenkPoley the Riak library was fixed quite a while ago, so I guess it's just a matter of bumping the dependency version.
I don't see anything specific Riak in my project's composer.lock, as I don't use it. Only that doctrine/cache is v1.8.0, which seems to be latest.
Still the simplest explanation to me, seems to be that rector is reading files from my vendor directory, and the global vendor directory, and getting confused halfway. The error also talks about both directories at the same time.
If I could make it ignore the global vendor directory, that would be fine for me. It's only there to contain rector's code, nothing for my project. IMHO local installs/requires should take precedent anyways. But maybe that's not the way it works in PHP / composer land.
Closing here as root of the problem lies in 3rd party code
With the side remark that this means that whole class of PHP software cannot use Rector at all; anything that uses Doctrine, and anything that depends on Doctrine for some of it's (unused) use cases. In my case doctrine/dbal, and I don't use Riak.
I personally use Rector on many Doctrine projects and don't have such problem - e.g. migration id to uuid set or removing unused Doctrine properties.
We had this issues in the past and 3rd party code needs to be correct to perform analysis. Missing or invalid classes cannot be easily bypassed.
If you find a way though, let me know so we can integrate it here.
Just a heads-up but with Laravel-5.5 and Rector 0.5.21 on otherwise much the same codebase, I'm not seeing the above problem anymore 🤷♂️
Thanks, that's great!