Skip to content

PSR2.ControlStructures.SwitchDeclaration can remove comments on the same line as the case statement while fixing #3352

Closed
@umherirrender

Description

@umherirrender

Describe the bug
Running PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE can remove comments which are on the same line as the case statement

Code sample

$test = 2;

switch ( $test ) {
	case 2: // comment followed by empty line

		echo "test 2";
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <rule ref="PSR2.ControlStructures.SwitchDeclaration" />
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcbf test.php ...
  3. The comment is gone.
$test = 2;

switch ( $test ) {
	case 2:
		echo "test 2";
}

Expected behavior
The remove of the empty line is correct, but the comment should stay from my point of view.

Versions (please complete the following information):

  • OS: Windows 10
  • PHP: 8.0
  • PHPCS: 3.6.0
  • Standard: -

Additional context
The fixer starts directly after the colon/scope opener to remove everything there, not at the end of the line

Seems an issue since the fix for #683, which ignores the comments, but does not adjust the fixer part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions