Rector: Possibility to specify an autoload

Created on 30 Jan 2018  路  12Comments  路  Source: rectorphp/rector

Since Rector uses project's autoload to analyze type of elements, it cannot be installed as project in standalone directory

Why not add the possibility to specify auto-load file with ability of auto-detection? It should be possible PHPStan does that thing.

It would permit later to create phar and/or docker images and run it even on old PHP versions.

EDIT: Plus, using composer bin plugin will install rector on an isolated directory which is the same thing as doing a create-project AFAIK. Am I right? So the issue will be the same.

All 12 comments

Sure. Could you prepare such feature?

No time right now for it. But I'm sure I'm not the only one interested about that! :wink:

@TomasVotruba May you please specify where the files are autoloaded on your project? Would be a good place to start the work. :-)

I prefer cooperative solutions of issues :)

I looked into code and.... what about this one?

Does that work for you?

Well, when I use this option, I have:

$ ~/tmp/rector/bin/rector process --autoload-file=vendor/autoload.php --level=symfony33 src

4 Loaded Rectors
================

 - Rector\Rector\Dynamic\ArgumentReplacerRector
 - Rector\Rector\Contrib\Symfony\Console\ConsoleExceptionToErrorEventConstantRector
 - Rector\Rector\Dynamic\ClassReplacerRector
 - Rector\Rector\Dynamic\MethodNameReplacerRector

Processing 607 files
====================

   0/607 [鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒]   0% < 1 sec

In ProcessCommand.php line 172:

  [Rector\Exception\Command\FileProcessingException]                  
  Processing of "src/AppBundle/Admin/AbstractAdmin.php" file failed.  


Exception trace:
 Rector\Console\Command\ProcessCommand->processFiles() at /home/sullivan/tmp/rector/src/Console/Command/ProcessCommand.php:137
 Rector\Console\Command\ProcessCommand->execute() at /home/sullivan/tmp/rector/vendor/symfony/console/Command/Command.php:252
 Symfony\Component\Console\Command\Command->run() at /home/sullivan/tmp/rector/vendor/symfony/console/Application.php:865
 Symfony\Component\Console\Application->doRunCommand() at /home/sullivan/tmp/rector/vendor/symfony/console/Application.php:241
 Symfony\Component\Console\Application->doRun() at /home/sullivan/tmp/rector/vendor/symfony/console/Application.php:143
 Symfony\Component\Console\Application->run() at /home/sullivan/tmp/rector/bin/rector:44

In ParserAbstract.php line 744:

  [Error]                                                             
  Call to undefined method PhpParser\Node\Name::isSpecialClassName()  


Exception trace:
 PhpParser\ParserAbstract->checkNamespace() at /home/sullivan/tmp/rector/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php:1122
 PhpParser\Parser\Php7->PhpParser\Parser\{closure}() at /home/sullivan/tmp/rector/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:285
 PhpParser\ParserAbstract->doParse() at /home/sullivan/tmp/rector/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:159
 PhpParser\ParserAbstract->parse() at /home/sullivan/tmp/rector/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php:51
 PhpParser\Parser\Multiple->tryParse() at /home/sullivan/tmp/rector/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php:32
 PhpParser\Parser\Multiple->parse() at /home/sullivan/tmp/rector/src/Parser/Parser.php:36
 Rector\Parser\Parser->parseFile() at /home/sullivan/tmp/rector/packages/NodeTraverserQueue/src/NodeTraverserQueue.php:52
 Rector\NodeTraverserQueue\NodeTraverserQueue->processFileInfo() at /home/sullivan/tmp/rector/src/Application/FileProcessor.php:49
 Rector\Application\FileProcessor->processFile() at /home/sullivan/tmp/rector/src/Console/Command/ProcessCommand.php:198
 Rector\Console\Command\ProcessCommand->processFile() at /home/sullivan/tmp/rector/src/Console/Command/ProcessCommand.php:169
 Rector\Console\Command\ProcessCommand->processFiles() at /home/sullivan/tmp/rector/src/Console/Command/ProcessCommand.php:137
 Rector\Console\Command\ProcessCommand->execute() at /home/sullivan/tmp/rector/vendor/symfony/console/Command/Command.php:252
 Symfony\Component\Console\Command\Command->run() at /home/sullivan/tmp/rector/vendor/symfony/console/Application.php:865
 Symfony\Component\Console\Application->doRunCommand() at /home/sullivan/tmp/rector/vendor/symfony/console/Application.php:241
 Symfony\Component\Console\Application->doRun() at /home/sullivan/tmp/rector/vendor/symfony/console/Application.php:143
 Symfony\Component\Console\Application->run() at /home/sullivan/tmp/rector/bin/rector:44

process [--dry-run] [--autoload-file AUTOLOAD-FILE] [--] <source> (<source>)...

Please note I have nikic/php-parser v3.1.3 on my project dependencies. I suspect an autoload conflict.

Having a .phar with re-named namespace would be a solution IMHO. And you may even submit it on https://phar.io/.

I may try to build one and test. Do you know some goods phar building tool? :-)

We may try this: https://github.com/humbug/php-scoper and box.

@Soullivaneuh I have never made a phar work.

Please note I have nikic/php-parser v3.1.3 on my project dependencies. I suspect an autoload conflict.

Yea, that's it. Good job to identify this!

Having a .phar with re-named namespace would be a solution IMHO. And you way even submit it on https://phar.io/.

Based on reported issues and composer conflicts, I agree.

We may try this: https://github.com/humbug/php-scoper and box.

Do you an idea how to automate that? Or better - some standalone repository demo with Rector?

I have never made a phar work.

Me neither, time to start! :-D

Do you an idea how to automate that? Or better - some standalone repository demo with Rector?

I don't know. It seems we don't have specifications about that. It could be a simple Travis configuration to build and push a phar.

PHPStan has is own compiler: https://github.com/fprochazka/phpstan-compiler but it's maybe quite overkill for IMHO.

Could you prepare simple prototype that just works for your case? That's we really need.
We can continue from there to official phar.

@TomasVotruba Not on my high priority work but when I'll go back to the rector integration of my company project, I'll give some time on it. :+1:

Ok. I'll be closing this issue as autoload works. It only needs to be documented.

Todo

  • [x] add --autoload-file to README.md

It only needs to be documented.

IMO, #177 should be reopened.

Was this page helpful?
0 / 5 - 0 ratings