False positive warning for Enum classes with methods
contentrail opened this issue · comments
valyoshin commented
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.