rector icon indicating copy to clipboard operation
rector copied to clipboard

Syntax error unexpected 'a' (T_STRING)

Open artatum opened this issue 5 years ago • 22 comments

Question

Hello. Win 10/Docker/Drupal 9 As said in the title when I run
rector process modules/custom/xxx --dry-run I get : Syntax error unexpected 'a' (T_STRING). I didn't find anything about this on Google, or here. It's the first time I use rector, it's on a fresh install. Any idea welcome.

artatum avatar Aug 02 '21 08:08 artatum

Hi, thanks for reporting. What is the output for --debug?

We'll need the exact file this crashes on.

TomasVotruba avatar Aug 02 '21 09:08 TomasVotruba

Nothing more. I tried on other custom modules as well.

artatum avatar Aug 02 '21 11:08 artatum

We'll need a file to reproduce. We cannot do any fix without it.

TomasVotruba avatar Aug 02 '21 14:08 TomasVotruba

Could you tell me what to do then ?

artatum avatar Aug 02 '21 15:08 artatum

I'll try :hugs: I don't use Docker, so I can only help with default composer install approach:

composer require rector/rector --dev
vendor/bin/rector process src --debug --dry-run

Then try to narrow scope it down to single diretory, where the error happens:

vendor/bin/rector process src/FirstDir --debug --dry-run
vendor/bin/rector process src/SecondDir --debug --dry-run

Then narrow scope it down to single file:

vendor/bin/rector process src/FirstDir/FirstFile.php --debug --dry-run
vendor/bin/rector process src/FirstDir/SecondFile.php --debug --dry-run

Then try to keep as few lines as possible in file - basically comment chunks of code in that file and re-run Rector on it:

vendor/bin/rector process src/FirstDir/FirstFile.php --debug --dry-run

Until the error disappears. When the errors disappears, it's in the commented line. That single line is what we look for.

TomasVotruba avatar Aug 02 '21 15:08 TomasVotruba

Ok. I will do that. Thx for the steps.

artatum avatar Aug 03 '21 05:08 artatum

I created one file called info.php, into /docroot containing

phpinfo(); drupal_set_message("done");

I stil get [ERROR] syntax error, unexpected 'a' (T_STRING) :(

artatum avatar Aug 03 '21 06:08 artatum

Bingo ! It was my fault. :( A typo in rector.php. So I perfectly got [OK] Rector is done!

But on my dummy file or on my custom module I didn't get any diff displayed. (yet, drupal_set_message() is deprecated...) I've set two libraries in rector.php $containerConfigurator->import(SetList::DEAD_CODE); $containerConfigurator->import(SetList::CODE_QUALITY);

artatum avatar Aug 03 '21 06:08 artatum

Well, things changed : I just moved to another branch, went back, and rector doesn't work anymore. I now get : [ERROR] Unable to write in the "cache" directory (/tmp/rector/cache). I created those directories, set them to 777. But it doesn't work.

artatum avatar Aug 03 '21 09:08 artatum

A typo in rector.php.

Congrats :+1: Just curious, what was the typo? :)

Unable to write in the "cache" directory (/tmp/rector/cache).

That seems like filesystem and Rector are running under different user. Try to use the same one.

TomasVotruba avatar Aug 03 '21 09:08 TomasVotruba

A stupid comment (//) deleted on the wrong line. One owner is ww-data (rector) and tmp is wodby. I tried chown wodby rector.php, but I get the same error. I'm under docker : how can I set the same user for both please ?

artatum avatar Aug 03 '21 11:08 artatum

A stupid comment (//) deleted on the wrong line.

I see :+1: That happens, I've been there :). Maybe it would be helpful to have https://getrector.org/demo link next time. It's easier to spot these by somebody else.

I'm under docker : how can I set the same user for both please ?

I'm not using Rector with Docker, so I'm not sure. This would be generic Docker issue IMO, unrelated to Rector.

Based on feedback from few issue reports, it might save you couple of hours to use composer version over Docker one. It has much better support and I'm thinking of promoting it better. In the end Rector should be part of your project for long-term maintenance, same way PHPUnit is.

TomasVotruba avatar Aug 03 '21 12:08 TomasVotruba

Sorry, I dont understand what you mean by 'use composer version over Docker one'. I'm using a global composer installed on my Win 10. Any action is mirrored into the container. I dont understand why it was working this morning, though.

artatum avatar Aug 03 '21 12:08 artatum

'use composer version over Docker one'.

No problem. I meant like this: https://github.com/rectorphp/rector#install

I dont understand why it was working this morning, though.

That's one the toughest questoins :) access rights, cache and Windows can change very quickly... Maybe @staabm might help. Are you running Rector on Windows too?

TomasVotruba avatar Aug 03 '21 12:08 TomasVotruba

I destroyed and rebuilt the container : everything is back ! I ran a first command and got a warning : [WARNING] Your project requires min PHP version "7.4". Rector rules defined in your configuration require higher PHP version and will not run. Which php version is required for rector, and how can I set it plz ?

artatum avatar Aug 03 '21 12:08 artatum

Sorry, I have no experince with docker

staabm avatar Aug 03 '21 12:08 staabm

@artatum the warning is fine, that's just show you that some rector rules are require higher php version, you can try latest rector for more verbose warning message, and suggest to use -vvv to see what rules that require higher php version:

Screen Shot 2021-08-02 at 21 30 47

see https://github.com/rectorphp/rector-src/pull/574

samsonasik avatar Aug 03 '21 12:08 samsonasik

Is it this ?

  • [8.0] RemoveUnusedPromotedPropertyRector So what should I do ?

artatum avatar Aug 03 '21 12:08 artatum

No need, or if you don't want to see the warning, you can include in the skip option:

use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;

//...
    $parameters->set(Option::SKIP, [
        RemoveUnusedPromotedPropertyRector::class,
    ]);

samsonasik avatar Aug 03 '21 12:08 samsonasik

do you mean edit rector.php ?

artatum avatar Aug 03 '21 12:08 artatum