rector: Syntax error, unexpected T_NS_SEPARATOR, expecting ';' or '{' on line 3

Bug Report

Subject Details
Rector version e.g. v0.7.55
Installed as composer dependency

So I am not sure whether it’s a parser issue or a rector issue, but I ran vendor/bin/rector process app -v (I thought -v is verbose but it’s not the case I think)

with this config (rector.php in root folder)

<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();
    $parameters->set('php_version_features', '7.4');
};

I get this error


Rector v0.7.55
Config file: rector.php

[parsing] app/Console/Commands/GenerateAllModels.php

In ParserAbstract.php line 266:
                                                                           
  [PhpParser\Error]                                                        
  Syntax error, unexpected T_NS_SEPARATOR, expecting ';' or '{' on line 3  
                                                                           

Exception trace:
  at phar:///mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:266
 PhpParser\ParserAbstract->doParse() at phar:///mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:142
 PhpParser\ParserAbstract->parse() at phar:///mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php:48
 PhpParser\Parser\Multiple->tryParse() at phar:///mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php:31
 PhpParser\Parser\Multiple->parse() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/PhpParser/Parser/Parser.php:42
 Rector\Core\PhpParser\Parser\Parser->parseFileInfo() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/FileProcessor.php:165
 Rector\Core\Application\FileProcessor->parseAndTraverseFileInfoToNodes() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/FileProcessor.php:105
 Rector\Core\Application\FileProcessor->parseFileInfoToLocalCache() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/RectorApplication.php:271
 Rector\Core\Application\RectorApplication->Rector\Core\Application\{closure}() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/RectorApplication.php:214
 Rector\Core\Application\RectorApplication->tryCatchWrapper() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/RectorApplication.php:272
 Rector\Core\Application\RectorApplication->parseFileInfosToNodes() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/RectorApplication.php:135
 Rector\Core\Application\RectorApplication->runOnFileInfos() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Console/Command/ProcessCommand.php:237
 Rector\Core\Console\Command\ProcessCommand->execute() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Console/Command/AbstractCommand.php:34
 Rector\Core\Console\Command\AbstractCommand->run() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/symfony/console/Application.php:911
 Symfony\Component\Console\Application->doRunCommand() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Console/Application.php:101
 Rector\Core\Console\Application->doRun() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/bin/rector:86

If I remove the -v modifier, I get this instead

Rector v0.7.55
Config file: rector.php

  910/1316 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░]  69%PHP Notice:  Undefined index: /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/app/Console/Commands/GenerateAllModels.php in /mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/src/Application/TokensByFilePathStora
ge.php on line 29

(the notice is getting out many times)

After these, I get some errrors such as

                                                                                                                       
 [ERROR] Could not process "app/Console/Commands/GenerateAllModels.php" file, due to:                                   
         "Syntax error, unexpected T_NS_SEPARATOR, expecting ';' or '{' on line 3".                                     

Or also

 [ERROR] Could not process "app/helpers.php" file, due to:                                                              
         "Return value of Rector\Core\Application\TokensByFilePathStorage::getForFileInfo() must be an instance of      
         Rector\Core\ValueObject\Application\ParsedStmtsAndTokens, null returned".                                      
           

Minimal PHP Code Causing Issue


<?php

namespace App\Console\Commands;

class Command {}

class GenerateAllModels extends Command
{
}

Expected Behaviour

I can’t show you the demo permalink because I got this warning

[WARNING] You are using YAML format in “…/project/rector.yaml” config. It will be removed in Rector 0.8. Switch to PHP format as soon as possible with “https://github.com/migrify/config-transformer” { “meta”: { “version”: “0.8.x-dev@82d3304”, “config”: “/project/rector.yaml” }, “totals”: { “changed_files”: 0, “removed_and_added_files_count”: 0, “removed_node_count”: 0, “errors”: 0 } }

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Now it’s giving me

 [ERROR] Could not process "app/Services/KmlParser.php" file, due to:                                                   
         "Analyze error: "Class Eloquent not found.". Include your files in "parameters > autoload_paths".              
         See https://github.com/rectorphp/rector#extra-autoloading".                                                    
                                                                 

will try to manually add it in a minute, but shouldn’t it just take the composer autoloader?