Skip to content

PHP 8.1 enum recognised as goto statement #3587

@mmarton

Description

@mmarton

Describe the bug
PHP 8.1 enum recognised as goto statement

Code sample

enum Status: int
{
    case ACTIVE = 1;
    case ARCHIVE = 2;
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="mine"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
    <rule ref="PSR12"/>
    <rule ref="Generic.PHP.DiscourageGoto"/>
</ruleset>

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
----------------------------------------------------------------------
FOUND 5 ERRORS AND 1 WARNING AFFECTING 5 LINES
----------------------------------------------------------------------
  9 | WARNING | [ ] Use of the GOTO language construct is
    |         |     discouraged
    |         |     (Generic.PHP.DiscourageGoto.Found)
 12 | ERROR   | [x] Line indented incorrectly; expected 0 spaces,
    |         |     found 4
    |         |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 14 | ERROR   | [x] Line indented incorrectly; expected 0 spaces,
    |         |     found 4
    |         |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 16 | ERROR   | [x] Line indented incorrectly; expected 0 spaces,
    |         |     found 4
    |         |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 17 | ERROR   | [x] Expected 1 blank line at end of file; 2 found
    |         |     (PSR2.Files.EndFileNewline.TooMany)
 17 | ERROR   | [x] Line indented incorrectly; expected at least 4
    |         |     spaces, found 0
    |         |     (Generic.WhiteSpace.ScopeIndent.Incorrect)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expected behavior
no errors

Versions (please complete the following information):

  • OS: linux mint
  • PHP: 8.1
  • PHPCS: latest (3.6.2)
  • Standard: PSR12

Additional context
the reported indentation problems already have a closed issue here: #3474

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions