PHPCompatibility / PHPCompatibility

PHP Compatibility check for PHP_CodeSniffer

Home Page:http://techblog.wimgodden.be/tag/codesniffer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive warning for Enum classes with methods

contentrail opened this issue · comments

Bug Description

Compatibility check against Enum classes with methods provides wrong warnings:
"$this" can no longer be used in a plain function or method since PHP 7.1.

Given the following reproduction Scenario

The issue happens when running this command:

phpcs -ps file.php --standard=PHPCompatibility --runtime-set testVersion 8.1

... over a file containing this code:

<?php

declare(strict_types=1);

namespace App\Entity;

enum PaymentOption: string
{
    case CARD = 'CARD';
    case POINTS = 'POINTS';

    public function isCard(): bool
    {
        return $this === self::CARD;
    }
}

I'd expect the following behaviour

Provided enum class is completely compatible with php 8.1.
php documentation

Instead this happened

FILE: /app/src/Entity/PaymentOption.php
-----------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------
 14 | ERROR | "$this" can no longer be used in a plain function or method since PHP 7.1.
-----------------------------------------------------------------------------------------

Environment

Environment Answer
PHP version 8.1.12
PHP_CodeSniffer version 3.7.1
PHPCompatibility version 9.3.5
Install type Composer project local

Additional Context (optional)

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of PHPCompatibility.

Closing this as a duplicate of #1343, which has already been fixed by the upgrade to PHPCSUtils 1.0.0-alpha4. Also see #1364.

P.S.: please don't check the "I have verified the issue still exists in the develop branch of PHPCompatibility." checkbox if you haven't checked.