Rector: "config/set/code-quality.php" was not found (and all others too)

Created on 23 Sep 2020  路  16Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| rector/rector-prefixed | v0.8.7@869441e |
| Installed as | prefixed Rector PHAR |

Good morning

Since days, I can't use anymore my preferred static analysis quality tool because for an unknown reason my rector.php file can't be processed correctly. Rector is saying that my list of SETS are no more correct.

This is my command:

vendor\bin\rector.bat process --dry-run --config C:\Christophe\.config\rector.php C:\Christophe\src\classes\WebService.php

And I get immediately:

[ERROR] Set
         "phar://C:/Users/Christophe/AppData/Roaming/Composer/vendor/rector/rector-prefixed/rector/packages/se
         t/src/ValueObject/../../../../config/set/code-quality.php" was not found

 ! [NOTE] Pick one of:

 * defluent
 * action-injection-to-constructor-injection
 * array-str-functions-to-static-call
 * cakephp30
 * cakephp34
 * cakephp35
 * cakephp36
 * ...

To make sure I've copied/pasted the rector.php sample given in your readme.md file (on the repo page) and still the same problem.

Minimal PHP Code Causing Issue

This isn't a problem with my .php source but with the config file but, in case, here is my rector config: https://getrector.org/demo/dbb6b91d-7d80-4883-b547-405505c62217#result

Expected Behaviour

Rector need to retrieve the list of rules that are part of the provided Options::SETS array.

Many thanks!

bug prefixed

All 16 comments

Hi,

thanks for reporting issue.

This will be most likely related to Windows paths.

The set object is resolved based on path: https://github.com/symplify/set-config-resolver/blob/28d6a4174da548e7b73ead8be349e6908a0f2eb9/src/Provider/AbstractSetProvider.php#L62

Thanks Tomas

Sorry, I'm a coding on a Windows machine ;) (but if it can highlights issues, it's fine too)

_Note: It was well working in a previous version of Rector_

Could you try to download Rector via composer dependency and tune this part https://github.com/symplify/set-config-resolver/blob/28d6a4174da548e7b73ead8be349e6908a0f2eb9/src/Provider/AbstractSetProvider.php#L62 to to make it work?

Then we'd have a fix :)

Updating line 62 to $setPath = Strings::after(\realpath($setPath), DIRECTORY_SEPARATOR, -2); seems to work.

Just calling the realpath() function has solve the issue on a dummy repo I've just created with a -dev dependency to rector/rector.

Nice.
Does the realpath work in phar too? AFAIK it's broken there

Sorry not sure to know what I need to do...

You mean rector.phar in my C:\Users\Christophe\AppData\Roaming\Composer\vendor\rector\rector-prefixed folder ? That file is 29MB big, don't know how to edit it... but yes, my global dependendy (rector-prefixed) is still broken.

My test here above was on a fake repo where rector was possible to install.

On my current project, I just can't install rector due to composer conflicts.

Well, to make sure it works inside phar, the following is needed:

  • unpack rector.phar with box

    • the command is something like box.phar extract rector.phar

  • change the file you've changed
  • pack it back with box.phar compile command
  • run it with set to verify, the bug is fixed

No need to install it to your project, this is project independent.

If that is working and allright, we can merge the change :+1:

Hello Tomas

I've tried...

Extraction done (box.phar extract rector.phar .) and the mentionned file has been updated update (but this time, the line wasn't line 62 but 52).

Then box.phar compile seems to create two new files in the /bin folder. Not sure what I need to do so I copy the two files from bin to the root folder of the rector-prefixed folder.

Once in my project root folder, I run vendor\bin\rector process src --dry-run --config src\rector.php once more but didn't work due to problems in the compiled version of rector-prefixed:

Fatal error: Uncaught Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in C:\Christophe\test\vendor\rector\rector-prefixed\rector on line 34

Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in C:\Christophe\test\vendor\rector\rector-prefixed\rector on line 34

Call Stack:
    0.4096     428120   1. {main}() C:\Christophe\test\vendor\rector\rector-prefixed\rector:0

Thanks for going into this. The issue you have might be related to presence of multiple /vendor and rector / rector.phar files there. It's bette to have just 1 Rector/phar/vendor at one time.

and the mentionned file has been updated update

That's interesting. The bug will be somewhere in the phar then. I'm not sure what to try, as I haven't used Windows for 9 years.

How does it work when you only unpack the phar file and run the unpacked bin/rector?
That way we could see if it's Phar related.

Any update on this?
Reproducible Github repository with failing Github Action might help

Hi Tomas,

Sorry, not yet tried again to regenerate a phar...

But yes, the problem still occurs (I've made a global composer update of rector-prefixed this morning) and the problem is still there with the latest release.

The solution would be to just edit one file and make a fresh version of the phar. Editing the file was OK (https://github.com/rectorphp/rector/issues/4278#issuecomment-697329423) but since I didn't have skills for phar, I've tried and that process was KO on my machine (https://github.com/rectorphp/rector/issues/4278#issuecomment-698149947)

That would no work, as realpath does not work in phar files - https://bugs.php.net/bug.php?id=52769

What exact values is in $setPath before and after there?

image

Hi Tomas

Sorry for the delay, I waited until I had a little more time (a day off) to take a look at it, which I did this morning.

And I still can't understand / succeed to determine what I need to do and to solve that issue on my side.

So, this morning, I've created a fresh environment i.e. remove rector-prefixed from my Windows global composer.json and install an fresh rector-prexifed as a project's dependency.

First, I try to create a new rector.php configuration file and, same problem here i.e. it seems there is a problem with Windows filepaths as far I understand.

2020-10-23_10h07_47

So, just after the installation, I try vendor\bin\rector process --dry-run src and get the same error as mentionned in my first post i.e.

2020-10-23_10h31_11

Will I have better luck starting a Git Bash session? No.

2020-10-23_10h29_14

Ok, start now with box.

I've installed it as a project's dev dependency and when done, I run vendor/bin/box extract vendor/rector/rector-prexifed/rector.phah vendor/rector/rector-prexifed/ from my project's root folder.

Before running box, in my vendor/rector/rector-prefixed/ folder, I've this content: (I've well a rector.phar file).

2020-10-23_10h36_54

After box, in my vendor/rector/rector-prefixed/ folder, I've now (no more rector.phar):

2020-10-23_10h38_09

Once rector.phar has been extracted, I don't have anymore a rector file so, ok, I can't run vendor/bin/rector again... (I get No such file or directory which is correct since vendor/bin/rector is trying to start ../rector/rector-prefixed/rector; doesn't exists anymore).

Ok, but now, how can I run rector? It seems stupid but I didn't know... (never work at all with compiling/extracting .phar files).
I see that I've a bin/rector php script in the rector-prefixed folder so let's try to update vendor/bin/rector and change the line

SET BIN_TARGET=%~dp0/../rector/rector-prefixed/bin/rector

to

SET BIN_TARGET="C:\temp\rector\vendor\rector\rector-prefixed\bin\rector"

No... Not the good way.

2020-10-23_10h46_27

I think I'll stop to use rector-prefixed as a global dependency

At this point, I think I should stop using rector-prefixed and hope that rector can be installed as a local dependency in each of my projects.

Sorry I couldn't do better than that.

Have a nice day.

Hi,

wow, that looks like a lot of effort. I've been through similar road few times, so I know how tiresome this is.

I would love to help, unfortunately I don't use Windows and have no knowledge about phar edge cases there

I'll try to help in a different perspective.

I think I'll stop to use rector-prefixed as a global dependency

Rector is not designed for global dependency and does not work there. Prefixed or non-prefixed. Either composer dependency, or prefixed phar.


Another view... What is the blocker for Rector as composer dependency? It might be easier to solve that

This issue will be solved soon with un-pharred package scoping - see https://github.com/symplify/package-scoper

ECS and MonorepoBuilder already use this technique, and it's way better with debugging and paths

Closing as last issue is dupplicate of https://github.com/rectorphp/rector/issues/4736

The Rector scooping will be handled in completely different way in Rector 0.9

Was this page helpful?
0 / 5 - 0 ratings