Skip to content

Commit 7b14021

Browse files
committed
SlevomatCodingStandard.PHP.UselessParentheses: Option "enableCheckAroundNew" is disabled if target PHP version is lower 8.4
1 parent e46bcbc commit 7b14021

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

SlevomatCodingStandard/Helpers/SniffSettingsHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,15 @@ public static function isEnabledByPhpVersion(?bool $value, int $phpVersionLimit)
7979
return $value;
8080
}
8181

82-
$phpVersion = Config::getConfigData('php_version') !== null ? (int) Config::getConfigData('php_version') : PHP_VERSION_ID;
82+
$phpVersion = self::getPhpVersion() ?? PHP_VERSION_ID;
8383
return $phpVersion >= $phpVersionLimit;
8484
}
8585

86+
public static function getPhpVersion(): ?int
87+
{
88+
$phpVersion = Config::getConfigData('php_version');
89+
90+
return $phpVersion !== null ? (int) $phpVersion : null;
91+
}
92+
8693
}

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHP_CodeSniffer\Util\Tokens;
88
use SlevomatCodingStandard\Helpers\FixerHelper;
99
use SlevomatCodingStandard\Helpers\IdentificatorHelper;
10+
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
1011
use SlevomatCodingStandard\Helpers\TokenHelper;
1112
use function array_key_exists;
1213
use function array_map;
@@ -119,6 +120,13 @@ public function register(): array
119120

120121
public function process(File $phpcsFile, int $parenthesisOpenerPointer): void
121122
{
123+
// @codeCoverageIgnoreStart
124+
$phpVersion = SniffSettingsHelper::getPhpVersion();
125+
if ($phpVersion !== null && $phpVersion < 80400) {
126+
$this->enableCheckAroundNew = false;
127+
}
128+
// @codeCoverageIgnoreEnd
129+
122130
$tokens = $phpcsFile->getTokens();
123131

124132
if (array_key_exists('parenthesis_owner', $tokens[$parenthesisOpenerPointer])) {

0 commit comments

Comments
 (0)