Syntax error unexpected 'a' (T_STRING)
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.
Hi, thanks for reporting.
What is the output for --debug?
We'll need the exact file this crashes on.
Nothing more. I tried on other custom modules as well.
We'll need a file to reproduce. We cannot do any fix without it.
Could you tell me what to do then ?
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.
Ok. I will do that. Thx for the steps.
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) :(
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);
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.
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.
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 ?
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.
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.
'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?
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 ?
Sorry, I have no experince with docker
@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:

see https://github.com/rectorphp/rector-src/pull/574
Is it this ?
- [8.0] RemoveUnusedPromotedPropertyRector So what should I do ?
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,
]);
do you mean edit rector.php ?