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

Error when running StringExtensionToConfigBuilderRector on simple configuration file #663

Open
reech-jeanphilippe opened this issue Aug 21, 2024 · 4 comments

Comments

@reech-jeanphilippe
Copy link

PHP version: 8.3.9
Symfony version: 7.1
Rector version: 1.2.3

See demo here: https://getrector.com/demo/de776077-7f25-484f-bfea-1f5cf23a0443.

Applying the StringExtensionToConfigBuilderRector rule to this file:

<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Http\Discovery\Psr17Factory;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;

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

    $services->alias(RequestFactoryInterface::class, 'http_discovery.psr17_factory');

    $services->alias(ResponseFactoryInterface::class, 'http_discovery.psr17_factory');

    $services->alias(ServerRequestFactoryInterface::class, 'http_discovery.psr17_factory');

    $services->alias(StreamFactoryInterface::class, 'http_discovery.psr17_factory');

    $services->alias(UploadedFileFactoryInterface::class, 'http_discovery.psr17_factory');

    $services->alias(UriFactoryInterface::class, 'http_discovery.psr17_factory');

    $services->set('http_discovery.psr17_factory', Psr17Factory::class);
};

results in this error:

[ERROR] Could not process "config/packages/http_discovery.php" file, due to:                                           
         "System error: "Split extensions "" to multiple separated files first"                                         
                                                                                                                        
         Stack trace:                                                                                                   
         #0                                                                                                             
         vendor/rector/rector/vendor/rector/rector-symfony/rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuild
         erRector.php(130):                                                                                             
         Rector\Symfony\NodeAnalyzer\SymfonyClosureExtensionMatcher->match(Object(PhpParser\Node\Expr\Closure))         
         #1 vendor/rector/rector/src/Rector/AbstractRector.php(139):                                                    
         Rector\Symfony\CodeQuality\Rector\Closure\StringExtensionToConfigBuilderRector->refactor(Object(PhpParser\Node 
         \Expr\Closure))                                                                                                
         #2 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(113):                          
         Rector\Rector\AbstractRector->enterNode(Object(PhpParser\Node\Expr\Closure))                                   
         #3 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):                          
         PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Return_))                                     
         #4 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):                          
         PhpParser\NodeTraverser->traverseArray(Array)                                                                  
         #5 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):                          
         PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Namespace_))                                  
         #6 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(85):                           
         PhpParser\NodeTraverser->traverseArray(Array)                                                                  
         #7 vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php(41):                               
         PhpParser\NodeTraverser->traverse(Array)                                                                       
         #8 vendor/rector/rector/src/Application/FileProcessor.php(113):                                                
         Rector\PhpParser\NodeTraverser\RectorNodeTraverser->traverse(Array)                                            
         #9 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(184):                                     
         Rector\Application\FileProcessor->processFile(Object(Rector\ValueObject\Application\File),                     
         Object(Rector\ValueObject\Configuration))                                                                      
         #10 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(161):                                    
         Rector\Application\ApplicationFileProcessor->processFile(Object(Rector\ValueObject\Application\File),          
         Object(Rector\ValueObject\Configuration))                                                                      
         #11 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(138):                                    
         Rector\Application\ApplicationFileProcessor->processFiles(Array, Object(Rector\ValueObject\Configuration),     
         Object(Closure), Object(Closure))                                                                              
         #12 vendor/rector/rector/src/Console/Command/ProcessCommand.php(131):                                          
         Rector\Application\ApplicationFileProcessor->run(Object(Rector\ValueObject\Configuration),                     
         Object(RectorPrefix202408\Symfony\Component\Console\Input\ArgvInput))                                          
         #13 vendor/rector/rector/vendor/symfony/console/Command/Command.php(327):                                      
         Rector\Console\Command\ProcessCommand->execute(Object(RectorPrefix202408\Symfony\Component\Console\Input\ArgvI 
         nput), Object(RectorPrefix202408\Symfony\Component\Console\Output\ConsoleOutput))                              
         #14 vendor/rector/rector/vendor/symfony/console/Application.php(960):                                          
         RectorPrefix202408\Symfony\Component\Console\Command\Command->run(Object(RectorPrefix202408\Symfony\Component\ 
         Console\Input\ArgvInput), Object(RectorPrefix202408\Symfony\Component\Console\Output\ConsoleOutput))           
         #15 vendor/rector/rector/vendor/symfony/console/Application.php(333):                                          
         RectorPrefix202408\Symfony\Component\Console\Application->doRunCommand(Object(Rector\Console\Command\ProcessCo 
         mmand), Object(RectorPrefix202408\Symfony\Component\Console\Input\ArgvInput),                                  
         Object(RectorPrefix202408\Symfony\Component\Console\Output\ConsoleOutput))                                     
         #16 vendor/rector/rector/src/Console/ConsoleApplication.php(53):                                               
         RectorPrefix202408\Symfony\Component\Console\Application->doRun(Object(RectorPrefix202408\Symfony\Component\Co 
         nsole\Input\ArgvInput), Object(RectorPrefix202408\Symfony\Component\Console\Output\ConsoleOutput))             
         #17 vendor/rector/rector/vendor/symfony/console/Application.php(216):                                          
         Rector\Console\ConsoleApplication->doRun(Object(RectorPrefix202408\Symfony\Component\Console\Input\ArgvInput), 
         Object(RectorPrefix202408\Symfony\Component\Console\Output\ConsoleOutput))                                     
         #18 vendor/rector/rector/bin/rector.php(130): RectorPrefix202408\Symfony\Component\Console\Application->run()  
         #19 vendor/rector/rector/bin/rector(5): require_once('/var/www/influe...')                                     
         #20 vendor/bin/rector(119): include('/var/www/influe...')                                                      
         #21 {main}". On line: 40

Thanks.

@TomasVotruba
Copy link
Member

Thank you for your report and demo link!

We'll need a failing test case in a pull-request, so we have it covered in Rector.
You can click "Create a Test" button at demo page.

@reech-jeanphilippe
Copy link
Author

Wow, you're fast !

I don't see this button on the demo page.

image

@samsonasik
Copy link
Member

The button not shown due to crash, so rule list not shown as well, you can add fixture to https://github.com/rectorphp/rector-symfony/tree/main/rules-tests/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector/Fixture , I think this should be skipped for no extension definition.

@reech-jeanphilippe
Copy link
Author

OK, I'll do that tomorrow.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants