Skip to content

Commit 3f7b29d

Browse files
committed
cs
1 parent 6983f95 commit 3f7b29d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Rules/PHPUnit/AttributeRequiresPhpVersionRule.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
namespace PHPStan\Rules\PHPUnit;
44

5-
use Composer\Semver\Constraint\ConstraintInterface;
6-
use Composer\Semver\VersionParser;
75
use PharIo\Version\UnsupportedVersionConstraintException;
86
use PharIo\Version\Version;
9-
use PharIo\Version\VersionConstraint;
107
use PharIo\Version\VersionConstraintParser;
118
use PhpParser\Node;
129
use PHPStan\Analyser\Scope;
@@ -15,20 +12,20 @@
1512
use PHPStan\Rules\Rule;
1613
use PHPStan\Rules\RuleErrorBuilder;
1714
use PHPUnit\Framework\TestCase;
18-
use UnexpectedValueException;
1915
use function count;
2016
use function is_numeric;
2117
use function method_exists;
2218
use function preg_match;
2319
use function sprintf;
20+
use function version_compare;
2421

2522
/**
2623
* @implements Rule<InClassMethodNode>
2724
*/
2825
class AttributeRequiresPhpVersionRule implements Rule
2926
{
30-
private const VERSION_COMPARISON = "/(?P<operator>!=|<|<=|<>|=|==|>|>=)?\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m";
3127

28+
private const VERSION_COMPARISON = "/(?P<operator>!=|<|<=|<>|=|==|>|>=)?\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m";
3229

3330
private Version $phpstanPhpVersion;
3431

@@ -95,13 +92,7 @@ public function processNode(Node $node, Scope $scope): array
9592
continue;
9693
}
9794
} catch (UnsupportedVersionConstraintException $e) {
98-
if (preg_match(self::VERSION_COMPARISON, $args[0], $matches) > 0) {
99-
$operator = $matches['operator'] !== '' ? $matches['operator'] : '>=';
100-
101-
if (version_compare($this->phpstanPhpVersion->getVersionString(), $matches['version'], $operator)) {
102-
continue;
103-
}
104-
} else {
95+
if (preg_match(self::VERSION_COMPARISON, $args[0], $matches) <= 0) {
10596
$errors[] = RuleErrorBuilder::message(
10697
sprintf($e->getMessage()),
10798
)
@@ -110,6 +101,12 @@ public function processNode(Node $node, Scope $scope): array
110101

111102
continue;
112103
}
104+
105+
$operator = $matches['operator'] !== '' ? $matches['operator'] : '>=';
106+
107+
if (version_compare($this->phpstanPhpVersion->getVersionString(), $matches['version'], $operator)) {
108+
continue;
109+
}
113110
}
114111

115112
$errors[] = RuleErrorBuilder::message(

0 commit comments

Comments
 (0)