`PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc.ClosingMarkerNoNewLine` is reported for two different errors
anomiex opened this issue · comments
Bug Description
The code PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc.ClosingMarkerNoNewLine
is used for two different errors:
- Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.
- The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.
I'd like to exclude the first for files that are conditionally used for PHP 7.3+ only, but I can't because it would also exclude the second.
Given the following reproduction Scenario
The issue happens when running this command:
phpcs -ps file.php --standard=PHPCompatibility --runtime-set testVersion 7.0-
... over a file containing this code:
<?php
// This fails in PHP 7.2 and earlier
$x = <<<END
END . "\n";
// This fails in PHP 7.3+
$x = <<<END
END ING
END;
I'd expect the following behaviour
Two different error codes are produced, one for the two instances of the "in PHP 7.2 or earlier" issue and one for the instance of the "since PHP 7.3" issue.
Instead this happened
All three errors have the same code.
5 | ERROR | Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier. (PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc.ClosingMarkerNoNewLine)
9 | ERROR | Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier. (PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc.ClosingMarkerNoNewLine)
9 | ERROR | The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3. (PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc.ClosingMarkerNoNewLine)
Environment
Environment | Answer |
---|---|
PHP version | 8.2.17 |
PHP_CodeSniffer version | 3.9.0 |
PHPCSUtils version | 1.0.10 |
PHPCompatibility version | 9.3.5, dev-develop |
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.
@anomiex Thanks for reporting this! You are 100% correct, the intention was definitely to have a separate error code for each of the errors in the sniff. This was an oversight / copy/paste error (which apparently nobody noticed in the five years the sniff has existed so far... 😬) and should be fixed now via PR #1697.