Unexpected token in @ApiResource(normalizationContext={"groups"={"default"}})
Bug Report
| Subject | Details |
|---|---|
| Rector version | e.g. v0.10.4 (invoke vendor/bin/rector --version) |
| Installed as | composer dependency / prefixed Rector |
Using phpstan/phpdoc-parser 0.5.4.
Minimal PHP Code Causing Issue
namespace App\Entity;
use ApiPlatform\Core\Annotation as Api;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Entity\BaseRepository")
*
* @Api\ApiResource(
* normalizationContext={"groups"={"default"}},
* denormalizationContext={"groups"={"write"}},
* collectionOperations={"get"},
* itemOperations={"get"},
* order={"code"},
* paginationEnabled=false
* )
*/
class User extends BaseEntity
{
}
I'm getting this error:
[parsing] src/Entity/User/User.php [refactoring] src/Entity/User/User.php [applying] Rector\Renaming\Rector\Name\RenameClassRector [applying] Rector\CodeQuality\Rector\Name\FixClassCaseSensitivityNameRector
In TokenIterator.php line 141:
[PHPStan\PhpDocParser\Parser\ParserException]
Unexpected token ""default"", expected '}' at offset 38
However, this simple example works fine on getrector.org/demo. Any idea what's going wrong? If not, how can I improve this bug report?
Hi,
we've done an update on this in Rector 0.10.4. How does it behave in this version?
I'm sorry, I was already using 0.10.4.
I see. Could you provided minimal code that is causing this? Should be 1-2 docblock lines in the end.
Hello, I have the same issue. But I do not understand your last comment. What are you expecting? Thanks
Minimal docblock that creates this issues, e.g.
/** @Api(key={"value"}) */
The smaller the better :)
If guess it's that:
/**
* @ApiResource(
* collectionOperations={
* "get": {
* "pagination_items_per_page"=100,
* },
* },
* )
*/
class Foobar{}
That seems working https://getrector.org/demo/cf027daa-93b0-4fe7-9025-997f60757bab
https://github.com/stephanvierkant/rector-parser-exception
composer install
vendor/bin/rector process src/Entity/User.php --clear-cache -vvv
[parsing] src/Entity/User.php [refactoring] src/Entity/User.php [applying] Rector\Renaming\Rector\Name\RenameClassRector [applying] Rector\CodeQuality\Rector\Name\FixClassCaseSensitivityNameRector
In TokenIterator.php line 141:
[PHPStan\PhpDocParser\Parser\ParserException]
Unexpected token ""default"", expected '}' at offset 38
Thanks!
@stephanvierkant Could you add a simle failing Github Action there with --debug? That way we can see the debug output and quickly find the spot + verify it on the PR fix
in case it can help: in a controller with the same type of annotation
/**
* @ParamConverter("firstArticleQualificationFile", options={"mapping"={"fileId"="id", "id"="firstArticleQualification"}})
*/
using the --debug options, outputs:
[parsing] src/Controller/Quality/FirstArticleQualificationController.php
[refactoring] src/Controller/Quality/FirstArticleQualificationController.php
[applying] Rector\Renaming\Rector\Name\RenameClassRector
[applying] Rector\Arguments\Rector\MethodCall\ValueObjectWrapArgRector
[applying] Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector
Fatal error: Uncaught PHPStan\PhpDocParser\Parser\ParserException: Unexpected token "\"fileId\"", expected '}' at offset 54 in phar:///srv/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php:141
Stack trace:
#0 phar:///srv/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php(59): PHPStan\PhpDocParser\Parser\TokenIterator->throwError(32)
#1 /srv/vendor/rector/rector/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php(62): PHPStan\PhpDocParser\Parser\TokenIterator->consumeTokenType(32)
#2 /srv/vendor/rector/rector/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php(119): Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser->parserArray(Object(Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator))
#3 /srv/vendor/rector/rector/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php(75): Rector\BetterPhpDocParser\PhpDocParser\ in phar:///srv/vendor/phpstan/phpstan/phpstan.phar/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php on line 141
@TomasVotruba https://github.com/stephanvierkant/rector-parser-exception/runs/2332135735?check_suite_focus=true