Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Downgrade PHP 7.4] Class was not found while trying to analyse it #5252

Closed
leoloso opened this issue Jan 20, 2021 · 4 comments
Closed

[Downgrade PHP 7.4] Class was not found while trying to analyse it #5252

leoloso opened this issue Jan 20, 2021 · 4 comments
Labels

Comments

@leoloso
Copy link
Contributor

leoloso commented Jan 20, 2021

Bug Report

Subject Details
Rector version v0.9.7
Installed as composer dependency

Starting from Rector 0.9.7, downgrading Rector to PHP 7.1 fails:

 [ERROR] Could not process "vendor/symfony/cache/CacheItem.php" file, due to:   
         "Analyze error: "Class  was not found while trying to analyse it -     
         discovering symbols is probably not configured properly.". Include your
         files in "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" in         
         "rector.php" config.                                                   
         See https://github.com/rectorphp/rector#configuration".                
                                                                                

                                                                                
 [ERROR] Could not process "vendor/symfony/string/AbstractUnicodeString.php"    
         file, due to:                                                          
         "Analyze error: "Class  was not found while trying to analyse it -     
         discovering symbols is probably not configured properly.". Include your
         files in "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" in         
         "rector.php" config.                                                   
         See https://github.com/rectorphp/rector#configuration".                
                                                                                

                                                                                
 [ERROR] Could not process "vendor/symfony/string/ByteString.php" file, due to: 
         "Analyze error: "Class  was not found while trying to analyse it -     
         discovering symbols is probably not configured properly.". Include your
         files in "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" in         
         "rector.php" config.                                                   
         See https://github.com/rectorphp/rector#configuration".                
                                                                                

                                                                                
 [ERROR] Could not process "vendor/symfony/string/CodePointString.php" file, due
         to:                                                                    
         "Analyze error: "Class  was not found while trying to analyse it -     
         discovering symbols is probably not configured properly.". Include your
         files in "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" in         
         "rector.php" config.                                                   
         See https://github.com/rectorphp/rector#configuration".                
                                                                                

                                                                                
 [ERROR] Could not process "vendor/symfony/string/UnicodeString.php" file, due  
         to:                                                                    
         "Analyze error: "Class  was not found while trying to analyse it -     
         discovering symbols is probably not configured properly.". Include your
         files in "$parameters->set(Option::AUTOLOAD_PATHS, [...]);" in         
         "rector.php" config.                                                   
         See https://github.com/rectorphp/rector#configuration".                

Minimal PHP Code Causing Issue

https://getrector.org/demo/2b94998b-4282-4fdf-88a9-d6b8cfb8d3af

Expected Behaviour

Why is it searching for an empty class? Where is that coming from?

Btw, I did an update for 0.9.7 on class DowngradeContravariantArgumentTypeRector (to avoid applying the rule on __construct), but that's completely unrelated. Undoing this change, the error still happens, so it must be somewhere else.

@leoloso
Copy link
Contributor Author

leoloso commented Jan 24, 2021

I identified the minimal piece of code causing the bug:

https://getrector.org/demo/6ddc6db1-d418-4f63-b123-318adfd4137c

use Symfony\Contracts\Cache\ItemInterface;

abstract class CacheItemTest implements ItemInterface
{
    public function tag($tags): ItemInterface
    {
        return $this;
    }
}

@leoloso
Copy link
Contributor Author

leoloso commented Jan 24, 2021

Here is the minimal Rector config:

https://getrector.org/demo/471e8b57-277e-4f47-b429-8fa621cd73d2

use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeCovariantReturnTypeRector;
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();

    $services->set(DowngradeCovariantReturnTypeRector::class);
    $services->set(DowngradeReturnSelfTypeDeclarationRector::class);
};

The bug happens when both DowngradeCovariantReturnTypeRector and DowngradeReturnSelfTypeDeclarationRector are applied, and in the order above.

Either removing 1 of them, or changing their order, works well!

https://getrector.org/demo/597dacce-4600-4f47-ac0c-66e3b0a9fd1a

Solution?

To fix the issue right now, we can just change the order these 2 rules are executed in downgrade-php74.php

But is that the actual solution? Or is there still some bug, waiting to explode again? To find out, should take the output from executing the first rule, and check why the 2nd rule explodes with that input.

@TomasVotruba
Copy link
Member

@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 25, 2021

I got same error reported for a new class const fetch.

This is the fix: #5306

The bug was exactly on this line: https://github.com/rectorphp/rector/pull/5306/files#diff-016ad0c3bfe09fb4b758182a0ea0630b905923756ba947940e82c5364d4c2eabL53
It returned null as a class name without checking it further. Then self created a new class with name '', thus the bug

TomasVotruba added a commit that referenced this issue Nov 16, 2023
rectorphp/rector-src@52ef7b8 [Scoped] Remove unused vendor/symfony/service-contracts/Test on downgrade build (#5252)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants