Skip to content

Commit f2d7b64

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

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-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: 6 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,11 @@ public function register(): array
119120

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

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

0 commit comments

Comments
 (0)