Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

[ECS] NewlineInNestedAnnotationFixer exception #2083

Closed
enumag opened this issue Aug 18, 2020 · 10 comments
Closed

[ECS] NewlineInNestedAnnotationFixer exception #2083

enumag opened this issue Aug 18, 2020 · 10 comments
Labels

Comments

@enumag
Copy link
Member

enumag commented Aug 18, 2020

In FixerFileProcessor.php line 160:
                                                                               
  Fixing of "..." file by "Symplify\CodingStandard\Fixer\Annotation\Newline  
  InNestedAnnotationFixer" failed: Index invalid or out of range in file /usr  
  /app/vendor/friendsofphp/php-cs-fixer/src/Doctrine/Annotation/Tokens.php on  
   line 306                                                                    
                                                                               

In Tokens.php line 306:
                                 
  Index invalid or out of range  
@enumag enumag added the bug label Aug 18, 2020
@enumag
Copy link
Member Author

enumag commented Aug 18, 2020

Stacktrace:

In FixerFileProcessor.php line 160:
                                                                                                                                       
  [Symplify\EasyCodingStandard\FixerRunner\Exception\Application\FixerFailedException]                                                 
  Fixing of "..." file by "Symplify\CodingStandard\Fixer  
  \Annotation\NewlineInNestedAnnotationFixer" failed: Index invalid or out of range in file .../vendor/friendsofphp/php-cs-fixer/src/Doctrine/Annotation/Tokens.php on line 306                                                       
                                                                                                                                       

Exception trace:
  at .../vendor/symplify/easy-coding-standard/packages/fixer-runner/src/Application/FixerFileProcessor.php:160
 Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor->processTokensByFixer() at .../vendor/symplify/easy-coding-standard/packages/fixer-runner/src/Application/FixerFileProcessor.php:108
 Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor->processFile() at .../vendor/symplify/easy-coding-standard/src/Application/SingleFileProcessor.php:60
 Symplify\EasyCodingStandard\Application\SingleFileProcessor->processFileInfo() at .../vendor/symplify/easy-coding-standard/src/Application/EasyCodingStandardApplication.php:119
 Symplify\EasyCodingStandard\Application\EasyCodingStandardApplication->processFoundFiles() at .../vendor/symplify/easy-coding-standard/src/Application/EasyCodingStandardApplication.php:93
 Symplify\EasyCodingStandard\Application\EasyCodingStandardApplication->run() at .../vendor/symplify/easy-coding-standard/src/Console/Command/CheckCommand.php:96
 Symplify\EasyCodingStandard\Console\Command\CheckCommand->execute() at .../vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at .../vendor/symfony/console/Application.php:911
 Symfony\Component\Console\Application->doRunCommand() at .../vendor/symplify/package-builder/src/Console/HelpfulApplicationTrait.php:30
 Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->doRunCommandAndShowHelpOnArgumentError() at .../vendor/symplify/package-builder/src/Console/HelpfulApplicationTrait.php:21
 Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->doRunCommand() at .../vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at .../vendor/symplify/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php:65
 Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->doRun() at .../vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at .../vendor/symplify/easy-coding-standard/bin/ecs:100

In Tokens.php line 306:
                                 
  [RuntimeException]             
  Index invalid or out of range  
                                 

Exception trace:
  at .../vendor/friendsofphp/php-cs-fixer/src/Doctrine/Annotation/Tokens.php:306
 SplFixedArray->offsetSet() at .../vendor/friendsofphp/php-cs-fixer/src/Doctrine/Annotation/Tokens.php:306
 PhpCsFixer\Doctrine\Annotation\Tokens->offsetSet() at .../vendor/friendsofphp/php-cs-fixer/src/Doctrine/Annotation/Tokens.php:279
 PhpCsFixer\Doctrine\Annotation\Tokens->insertAt() at .../vendor/symplify/coding-standard/src/Fixer/Annotation/NewlineInNestedAnnotationFixer.php:112
 Symplify\CodingStandard\Fixer\Annotation\NewlineInNestedAnnotationFixer->processEndBracket() at .../vendor/symplify/coding-standard/src/Fixer/Annotation/NewlineInNestedAnnotationFixer.php:90
 Symplify\CodingStandard\Fixer\Annotation\NewlineInNestedAnnotationFixer->fixAnnotations() at .../vendor/friendsofphp/php-cs-fixer/src/AbstractDoctrineAnnotationFixer.php:60
 PhpCsFixer\AbstractDoctrineAnnotationFixer->applyFix() at .../vendor/friendsofphp/php-cs-fixer/src/AbstractFixer.php:75
 PhpCsFixer\AbstractFixer->fix() at .../vendor/symplify/easy-coding-standard/packages/fixer-runner/src/Application/FixerFileProcessor.php:158
 Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor->processTokensByFixer() at .../vendor/symplify/easy-coding-standard/packages/fixer-runner/src/Application/FixerFileProcessor.php:108
 Symplify\EasyCodingStandard\FixerRunner\Application\FixerFileProcessor->processFile() at .../vendor/symplify/easy-coding-standard/src/Application/SingleFileProcessor.php:60
 Symplify\EasyCodingStandard\Application\SingleFileProcessor->processFileInfo() at .../vendor/symplify/easy-coding-standard/src/Application/EasyCodingStandardApplication.php:119
 Symplify\EasyCodingStandard\Application\EasyCodingStandardApplication->processFoundFiles() at .../vendor/symplify/easy-coding-standard/src/Application/EasyCodingStandardApplication.php:93
 Symplify\EasyCodingStandard\Application\EasyCodingStandardApplication->run() at .../vendor/symplify/easy-coding-standard/src/Console/Command/CheckCommand.php:96
 Symplify\EasyCodingStandard\Console\Command\CheckCommand->execute() at .../vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at .../vendor/symfony/console/Application.php:911
 Symfony\Component\Console\Application->doRunCommand() at .../vendor/symplify/package-builder/src/Console/HelpfulApplicationTrait.php:30
 Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->doRunCommandAndShowHelpOnArgumentError() at .../vendor/symplify/package-builder/src/Console/HelpfulApplicationTrait.php:21
 Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->doRunCommand() at .../vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at .../vendor/symplify/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php:65
 Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication->doRun() at .../vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at .../vendor/symplify/easy-coding-standard/bin/ecs:100

@enumag
Copy link
Member Author

enumag commented Aug 18, 2020

I'm not exactly sure what this fixer is supposed to do but seems like something with Doctrine Annotations that contain other annotations? If that's the case then the only nested annotation in the file where it crashed was this:

/**
 * @ORM\Entity()
 * @ORM\Table(indexes={@ORM\Index(columns={"process_start"})})
 */
class ...

All other Doctrine Annotations in the file are non-nested.

@enumag
Copy link
Member Author

enumag commented Aug 18, 2020

Might have been fixed in #2084, I'll have to check...

@enumag
Copy link
Member Author

enumag commented Aug 20, 2020

Seems to be fixed now but the output is not what I would expect based on your tweet: https://twitter.com/VotrubaT/status/1295749739879829505

Before:

/**
 * @ORM\Entity()
 * @ORM\Table(indexes={@ORM\Index(columns={"process_start"})})
 */

After:

/**
 * @ORM\Entity()
 * @ORM\Table(indexes={
 * @ORM\Index(columns={"process_start"})
 * })
 */

Expected:

/**
 * @ORM\Entity()
 * @ORM\Table(indexes={
 *     @ORM\Index(columns={"process_start"})
 * })
 */

@TomasVotruba
Copy link
Member

See #2078

Resp.

image

@enumag
Copy link
Member Author

enumag commented Aug 20, 2020

Oh I see. So I should refactor my

$containerConfigurator->import(__DIR__ . '/vendor/symplify/easy-coding-standard/config/set/....php');

to use the SetList constants now... thanks!

But the SetList contains more sets that I knew about. Where can I look which sets are already a part of another set to avoid duplication? Should I use them in any specific order?

@enumag
Copy link
Member Author

enumag commented Aug 20, 2020

Okay... 2 things I'm wondering about...:

  1. Somehow the DoctrineAnnotationNewlineInNestedAnnotationFixer is active even when I don't have SetList::DOCTRINE_ANNOTATIONS included. This should not be the case in my opinion.

  2. Since we're using NewWithBracesFixer for regular new MyClass calls to change it to new MyClass(), I'm personally configuring the DoctrineAnnotationBracesFixer to with_braces (default is without_braces) for consistency. What do you think about making this default?

@TomasVotruba
Copy link
Member

TomasVotruba commented Aug 24, 2020

  1. Thanks for reporting. I forgot to exclude it here: https://github.com/symplify/symplify/blob/0879ce5e528f3106083acc062c8a40389f4ed9f1/packages/coding-standard/config/symplify.php#L21
    I'll include it in todays refactorings. Maybe more rules should be there

  2. Good idea, I'd love to have this consistence too. First the rule was configured the way you suggested. But the DoctrineAnnotationBracesFixer is written to add these () to any annotation, that is not in exclude list (very bad design choice; it should look only for Doctrine\... annotations), so this happens:

-@see some @type
+@see some @type()

Try it on your code. See this reported in the original PHP CS Fixer PR: PHP-CS-Fixer/PHP-CS-Fixer#2220 (comment)

@enumag
Copy link
Member Author

enumag commented Aug 24, 2020

  1. Yeah, I noticed that too when trying it out. Had to turn off this fixer completely because I don't want the without_braces one.

@TomasVotruba
Copy link
Member

👍

Closing as original issue is resolved

@enumag enumag closed this as completed Aug 27, 2020
@deprecated-packages deprecated-packages locked as resolved and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants