Php-cs-fixer: VisibilityRequiredFixer removes comments between access modifier and variable name

Created on 20 Oct 2018  Â·  2Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using ($ php -v):

=> PHP 7.2.11

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> PHP CS Fixer 2.13.0

The command you use to run PHP CS Fixer:

=> php-cs-fixer fix --rules visibility_required -- Test.php

The configuration file you are using, if any:

no config

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
<?php
declare(strict_types=1);

class Test
{
  private /* comment */ $private = 'private';
};
  • with unexpected changes applied when running PHP CS Fixer:
<?php
declare(strict_types=1);

class Test
{
  private $private = 'private';
};
  • with the changes you expected instead:
    no change, comment not removed
kinbug

Most helpful comment

This was a comment to disable an inspector warning in the IDE.
PHPStorm will only accept this if it is written in this place.

private /** @noinspection PhpUnusedPrivateFieldInspection */ $private = 'private';

I do not need this comment, but I figured it would be right to report the bug that this fixer removes comments.

All 2 comments

btw, what is the purpose of such comment ?

This was a comment to disable an inspector warning in the IDE.
PHPStorm will only accept this if it is written in this place.

private /** @noinspection PhpUnusedPrivateFieldInspection */ $private = 'private';

I do not need this comment, but I figured it would be right to report the bug that this fixer removes comments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kcloze picture kcloze  Â·  3Comments

vitek-rostislav picture vitek-rostislav  Â·  3Comments

ro0NL picture ro0NL  Â·  3Comments

ndench picture ndench  Â·  3Comments

datenmeister picture datenmeister  Â·  3Comments