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

Syntax error, unexpected T_NS_SEPARATOR, expecting ';' or '{' on line 3 #3834

Closed
genesiscz opened this issue Jul 30, 2020 · 15 comments
Closed
Labels

Comments

@genesiscz
Copy link
Contributor

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 } }

@TomasVotruba
Copy link
Member

Hi, thanks for perfect report!

Could you try dev-master, if the problem still persist? It should be fixed there
If not, I'll release a new tag.

@genesiscz
Copy link
Contributor Author

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?

@genesiscz
Copy link
Contributor Author

I am using an Eloquent mixin on my Models in app/models which is generated to help IDE hint the magic functions that are provided by Laravel. It is stated as @mixin Eloquent but is not meant to be load/included by a project.
Is there a way to ignore @mixin in DOCblocks? I autoloaded it for now but I am not sure it will work as expected.

Anyway now I get a memory leak present somehow.

image
vendor/bin/rector process app/Services/
Rector dev-master@7dae020
Config file: rector.php

2/152 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 1%Segmentation fault (core dumped)

martin@Martins-Rabbithole:/mnt/c/Users/admin/Dropbox/_php/RestaurantBack$ vendor/bin/rector process app/Services/ --debug
File "/mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/autoload.php" is about to be loaded in "AutoloadIncluder::includeCwdVendorAutoloadIfExists()" on line 102"
File "/mnt/c/Users/admin/Dropbox/_php/RestaurantBack/vendor/rector/rector/../../autoload.php" is about to be loaded in "AutoloadIncluder::autoloadProjectAutoloaderFile()" on line 136"
Rector dev-master@7dae020
Config file: rector.php

[parsing] app/Services/AddressService.php
[parsing] app/Services/BPayment/BPaymentClient.php
[parsing] app/Services/BPayment/Helpers/Item.php
[parsing] app/Services/BPayment/Hooks/BPaymentConfig.php
[parsing] app/Services/BPayment/Hooks/IConfigurator.php
[parsing] app/Services/CartService.php
Segmentation fault (core dumped)

@TomasVotruba
Copy link
Member

What specific lines in CartService.php cause this?

Try running only on the file

vendor/bin/rector p app/Services/CartService.php --debug

Then removing code line by line from the file and re-run Rector again, untill the error disappears. It should be 5-10 lines in the end.

@TomasVotruba
Copy link
Member

I'll release new Rector in few minutes

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 30, 2020

Done: https://github.com/rectorphp/rector/releases/tag/v0.7.56

Closing as former issue is resolved.

Please open new issue with the minimal PHP code that causes segfault.

@genesiscz
Copy link
Contributor Author

genesiscz commented Jul 30, 2020

This works

<?php

namespace App\Services;

use App\Models\Cart;
use Auth;
use Session;

class CartService
{
    /**
     * @return Cart
     */
    function initNewCart()
    {
        $cart = new Cart();
        return $cart;
    }
}

this won't

<?php

namespace App\Services;

use App\Models\Cart;
use Auth;
use Session;


class CartService
{
    /**
     * @return Cart
     */
    function initNewCart()
    {
        $cart = new Cart();
        $cart->price = 0.0; // this line causes it
        return $cart;
    }
}

The underlying property doesn't exist, it's only as a @Property float $price and is available via Laravel's Model magic. MAYBE the problem is that BaseModel, which I am extending in Cart class, is defined on two places: that generated ide helper & actual BaseModel class

image

@TomasVotruba
Copy link
Member

Let's keep it focused in one place: #3836

@jsamouh
Copy link

jsamouh commented Aug 2, 2020

Done: https://github.com/rectorphp/rector/releases/tag/v0.7.56

Closing as former issue is resolved.

Please open new issue with the minimal PHP code that causes segfault.

Why 0.756 use nikic/php-parser 4.7 now ?
We have some constraints to use only nikic/php-parser 4.6. Is it possible to have this bugfix for 4.6 also ?

@TomasVotruba
Copy link
Member

There should be newer versions, see:
https://packagist.org/packages/rector/rector

Could you verify the problem is still there?

@jsamouh
Copy link

jsamouh commented Aug 2, 2020

There should be newer versions, see:
https://packagist.org/packages/rector/rector

Could you verify the problem is still there?

The problem is still there using 0.7.55

@TomasVotruba
Copy link
Member

TomasVotruba commented Aug 2, 2020

I see even 0.7.59 version on packagist

@jsamouh
Copy link

jsamouh commented Aug 2, 2020

I see even 0.7.59 version on packagist

yes but it uses nikic/php-parser: ^4.7 wich we cannot have in our project, only 4.6

@TomasVotruba
Copy link
Member

We cannot use older php-parser version because of compatibility with PHPStan.

What's the minimal PHP code causing the issue?

That might be a bug in php-parser

@jsamouh
Copy link

jsamouh commented Aug 2, 2020

we use psalm in our project but nothing existing for codingmachine safe. So to prevent using stan only for codingmachine safe, we want to use rector as suggested here https://github.com/thecodingmachine/safe in our CI as rector --dry-run.
But psalm is only on nikic-phpparser 4.6 right now,,,

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

3 participants