Rector: DocBlocks are unnecessarily modified

Created on 3 Mar 2020  ยท  11Comments  ยท  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | v0.7.3 |
| Installed as | composer dependency |

After updating rector/rector from https://github.com/rectorphp/rector/compare/v0.6.13...v0.7.3, annotations in DocBlocks are unnecessarily modified

     }

     /**
-     * @return \Generator<array{0: null|string}>
+     * @return \Generator<array{0:null|string}>
      */
     public static function company(): \Generator
     {

or

 final class FooAction
 {
     /**
-     * @Route(
-     *     path="/foo/bar.{_format}",
-     *     name=BarAction::class,
-     *     methods="GET",
-     *     defaults={
-     *         "_format": "jsonld",
-     *         "_api_resource_class": Foo::class,
-     *         "_api_collection_operation_name": "foo",
-     *         "_api_receive": false,
-     *     }
-     * )
+     * @Route(     path="/foo/bar.{_format}",     name="App\Action\BarAction",     methods={"GET"},         defaults={"_format":"jsonld", "_api_resource_class":"App\Entity\Foo",         "_api_collection_operation_name":"foo", "_api_receive":false}         )
      */
     public function __invoke(Request $request): JsonResponse
     {

Minimal PHP Code Causing Issue

Tried to reproduce on https://getrector.org/demo/c62d2af4-c14b-4761-9880-b8e2701efee6#result, but the result there is different from what we observe locally.

     }

     /**
-     * @return \Generator<array{0: null|string}>
+     * @return \Generator<array{0: (null | string)}>
      */
     public static function email(): \Generator
     {

Also see https://getrector.org/demo/009c98cd-0e4b-4a44-a811-622640f2a4ae#result.

โ“ Perhaps it would make sense to indicate which version of rector/rector is available at https://getrector.org/demo?

Expected Behaviour

Since no rules have been specified that indicate that DocBlocks should be touched, DocBlocks should not be touched.

bug

Most helpful comment

@TomasVotruba

Here's an example that completely messes up the DocBlock:

https://getrector.org/demo/0ef65210-5dd4-4ae6-93d5-13bd1ec9f0c6#result

Again, why are the DocBlocks even touched in the first place when no rule has been configured that indicates that I want any of the DocBlocks to be touched?

All 11 comments

Same issue here. rector changes every method docblock in all classes, which make it really hard to review. A configuration to disable those changes (code style fixes in general) would be much appreciated.

edit: version 0.6.14 does not change docblock comments

These bugs needs to be fixed instead workaround.

Failing cases added in here helps: https://github.com/rectorphp/rector/tree/master/packages/better-php-doc-parser/tests/PhpDocInfo/PhpDocInfoPrinter/FixtureBasic

Most of the issues are now resolved.

If you find a new one, create new issue with demo link: https://getrector.org/demo

Thank you, @TomasVotruba - I will take a look.

@TomasVotruba

Here's an example that completely messes up the DocBlock:

https://getrector.org/demo/0ef65210-5dd4-4ae6-93d5-13bd1ec9f0c6#result

Again, why are the DocBlocks even touched in the first place when no rule has been configured that indicates that I want any of the DocBlocks to be touched?

Here is commit that shows how to add such test case:
https://github.com/rectorphp/rector/pull/3218/commits/c735cfb3eebd8eed59bc8b9b3cdf4d9dfe1de00d

Only with such fixture we're able to fix it. Closing as PR with test fixture is needed.

@TomasVotruba

Has this issue been fixed - or closed only?

Original reported issues is fixed

@TomasVotruba

Unfortunately, that is not the case.

Running

$ composer show | grep rector/rector

yields

rector/rector                        v0.7.22 Instant upgrade and refactoring of your PHP code

Running

$ vendor/bin/rector process --config rector.yaml

with the configuration used when reporting the issue yields

      *     "fall_item_output",
      * })
      * @Assert\NotBlank
-     * @Assert\Choice({
-     *     Tagdefinition::UEBERGANGSVERHALTEN_BEIBEHALTEN,
+     * @Assert\Choice({Tagdefinition::UEBERGANGSVERHALTEN_BEIBEHALTEN,
      *     Tagdefinition::UEBERGANGSVERHALTEN_ENTFERNEN,
-     *     Tagdefinition::UEBERGANGSVERHALTEN_BLOCKIEREN,
-     * })
+     *     Tagdefinition::UEBERGANGSVERHALTEN_BLOCKIEREN})
      *
+     *
      * @var string
      */
     private $uebergangsverhalten;

From my point of view as a user of rector/rector I do not see a reason for the tool at all to modify any DocBlock unless I instruct the tool via configuration to do so.

Why are all of the DocBlocks touched at all?

Was this page helpful?
0 / 5 - 0 ratings