Skip to content

Line indented incorrectly false positive when using match-expression inside switch case #3530

@i350

Description

@i350

Describe the bug
When I uses match-expression inside a switch-case, I get non logical error

Code sample

 switch ($appEnv) { case 'production': return ($foo == 'bar') ? 'prod' : 'production'; case 'staging': return match ($foo) { 'bar' => 'custom_1', 'baz' => 'custom_2', default => 'staging' }; case 'testing': return 'testing'; default: return 'default'; }

I get error starting from the line "case 'testing': .....'

Error: Line indented incorrectly; expected 12 spaces, found 8 

This require me to justify the "case 'testing':" with its body and "default:" case with its body to closing curly brace of match expression!
Like this:

 switch ($appEnv) { case 'production': return ($foo == 'bar') ? 'prod' : 'production'; case 'staging': return match ($foo) { 'bar' => 'custom_1', 'baz' => 'custom_2', default => 'staging' }; case 'testing': return 'testing'; default: return 'default'; }

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
PHPCS output here 

Expected behavior
A clear and concise description of what you expected to happen.

Versions (please complete the following information):

  • OS: Linux 050918c5cfc1 5.11.0-43-generic ~ 20.04.2-Ubuntu SMP x86_64
  • PHP: 8.0.13
  • PHPCS: 3.6.1 stable
  • Standard: PSR2

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