Skip to content

Commit d893ba0

Browse files
More
1 parent 29f701d commit d893ba0

15 files changed

+41
-37
lines changed

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,15 +747,15 @@ private function resolveType(string $exprString, Expr $node): Type
747747
}
748748

749749
if ($node instanceof Expr\BinaryOp\Smaller) {
750-
return $this->getType($node->left)->isSmallerThan($this->getType($node->right))->toBooleanType();
750+
return $this->getType($node->left)->isSmallerThan($this->getType($node->right), $this->phpVersion)->toBooleanType();
751751
}
752752

753753
if ($node instanceof Expr\BinaryOp\SmallerOrEqual) {
754754
return $this->getType($node->left)->isSmallerThanOrEqual($this->getType($node->right), $this->phpVersion)->toBooleanType();
755755
}
756756

757757
if ($node instanceof Expr\BinaryOp\Greater) {
758-
return $this->getType($node->right)->isSmallerThan($this->getType($node->left))->toBooleanType();
758+
return $this->getType($node->right)->isSmallerThan($this->getType($node->left), $this->phpVersion)->toBooleanType();
759759
}
760760

761761
if ($node instanceof Expr\BinaryOp\GreaterOrEqual) {

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ public function getType(Expr $expr, InitializerExprContext $context): Type
316316
}
317317

318318
if ($expr instanceof Expr\BinaryOp\Smaller) {
319-
return $this->getType($expr->left, $context)->isSmallerThan($this->getType($expr->right, $context))->toBooleanType();
319+
return $this->getType($expr->left, $context)->isSmallerThan($this->getType($expr->right, $context), $this->phpVersion)->toBooleanType();
320320
}
321321

322322
if ($expr instanceof Expr\BinaryOp\SmallerOrEqual) {
323323
return $this->getType($expr->left, $context)->isSmallerThanOrEqual($this->getType($expr->right, $context), $this->phpVersion)->toBooleanType();
324324
}
325325

326326
if ($expr instanceof Expr\BinaryOp\Greater) {
327-
return $this->getType($expr->right, $context)->isSmallerThan($this->getType($expr->left, $context))->toBooleanType();
327+
return $this->getType($expr->right, $context)->isSmallerThan($this->getType($expr->left, $context), $this->phpVersion)->toBooleanType();
328328
}
329329

330330
if ($expr instanceof Expr\BinaryOp\GreaterOrEqual) {

src/Rules/Functions/RandomIntParametersRule.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Expr\FuncCall;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\Php\PhpVersion;
89
use PHPStan\Reflection\ReflectionProvider;
910
use PHPStan\Rules\Rule;
1011
use PHPStan\Rules\RuleErrorBuilder;
@@ -21,8 +22,11 @@
2122
final class RandomIntParametersRule implements Rule
2223
{
2324

24-
public function __construct(private ReflectionProvider $reflectionProvider, private bool $reportMaybes)
25-
{
25+
public function __construct(
26+
private ReflectionProvider $reflectionProvider,
27+
private PhpVersion $phpVersion,
28+
private bool $reportMaybes
29+
) {
2630
}
2731

2832
public function getNodeType(): string
@@ -55,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array
5559
return [];
5660
}
5761

58-
$isSmaller = $maxType->isSmallerThan($minType);
62+
$isSmaller = $maxType->isSmallerThan($minType, $this->phpVersion);
5963

6064
if ($isSmaller->yes() || $isSmaller->maybe() && $this->reportMaybes) {
6165
$message = 'Parameter #1 $min (%s) of function random_int expects lower number than parameter #2 $max (%s).';

src/Type/CompoundType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog
1515

1616
public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult;
1717

18-
public function isGreaterThan(Type $otherType): TrinaryLogic;
18+
public function isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic;
1919

2020
public function isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic;
2121

src/Type/Enum/EnumCaseObjectType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function generalize(GeneralizePrecision $precision): Type
180180
return new parent($this->getClassName(), null, $this->getClassReflection());
181181
}
182182

183-
public function isSmallerThan(Type $otherType): TrinaryLogic
183+
public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
184184
{
185185
return TrinaryLogic::createNo();
186186
}

src/Type/IntegerRangeType.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,18 @@ public function generalize(GeneralizePrecision $precision): Type
308308
return new IntegerType();
309309
}
310310

311-
public function isSmallerThan(Type $otherType): TrinaryLogic
311+
public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
312312
{
313313
if ($this->min === null) {
314314
$minIsSmaller = TrinaryLogic::createYes();
315315
} else {
316-
$minIsSmaller = (new ConstantIntegerType($this->min))->isSmallerThan($otherType);
316+
$minIsSmaller = (new ConstantIntegerType($this->min))->isSmallerThan($otherType, $phpVersion);
317317
}
318318

319319
if ($this->max === null) {
320320
$maxIsSmaller = TrinaryLogic::createNo();
321321
} else {
322-
$maxIsSmaller = (new ConstantIntegerType($this->max))->isSmallerThan($otherType);
322+
$maxIsSmaller = (new ConstantIntegerType($this->max))->isSmallerThan($otherType, $phpVersion);
323323
}
324324

325325
return TrinaryLogic::extremeIdentity($minIsSmaller, $maxIsSmaller);
@@ -342,18 +342,18 @@ public function isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): T
342342
return TrinaryLogic::extremeIdentity($minIsSmaller, $maxIsSmaller);
343343
}
344344

345-
public function isGreaterThan(Type $otherType): TrinaryLogic
345+
public function isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
346346
{
347347
if ($this->min === null) {
348348
$minIsSmaller = TrinaryLogic::createNo();
349349
} else {
350-
$minIsSmaller = $otherType->isSmallerThan((new ConstantIntegerType($this->min)));
350+
$minIsSmaller = $otherType->isSmallerThan((new ConstantIntegerType($this->min)), $phpVersion);
351351
}
352352

353353
if ($this->max === null) {
354354
$maxIsSmaller = TrinaryLogic::createYes();
355355
} else {
356-
$maxIsSmaller = $otherType->isSmallerThan((new ConstantIntegerType($this->max)));
356+
$maxIsSmaller = $otherType->isSmallerThan((new ConstantIntegerType($this->max)), $phpVersion);
357357
}
358358

359359
return TrinaryLogic::extremeIdentity($minIsSmaller, $maxIsSmaller);
@@ -692,7 +692,7 @@ public function toPhpDocNode(): TypeNode
692692

693693
public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
694694
{
695-
if ($this->isSmallerThan($type)->yes() || $this->isGreaterThan($type)->yes()) {
695+
if ($this->isSmallerThan($type, $phpVersion)->yes() || $this->isGreaterThan($type, $phpVersion)->yes()) {
696696
return new ConstantBooleanType(false);
697697
}
698698

src/Type/IntersectionType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@ public function isCloneable(): TrinaryLogic
802802
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isCloneable());
803803
}
804804

805-
public function isSmallerThan(Type $otherType): TrinaryLogic
805+
public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
806806
{
807-
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isSmallerThan($otherType));
807+
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isSmallerThan($otherType, $phpVersion));
808808
}
809809

810810
public function isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
@@ -876,9 +876,9 @@ public function isInteger(): TrinaryLogic
876876
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isInteger());
877877
}
878878

879-
public function isGreaterThan(Type $otherType): TrinaryLogic
879+
public function isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
880880
{
881-
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $otherType->isSmallerThan($type));
881+
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $otherType->isSmallerThan($type, $phpVersion));
882882
}
883883

884884
public function isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic

src/Type/NullType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ public function equals(Type $type): bool
108108
return $type instanceof self;
109109
}
110110

111-
public function isSmallerThan(Type $otherType): TrinaryLogic
111+
public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
112112
{
113113
if ($otherType instanceof ConstantScalarType) {
114114
return TrinaryLogic::createFromBoolean(null < $otherType->getValue());
115115
}
116116

117117
if ($otherType instanceof CompoundType) {
118-
return $otherType->isGreaterThan($this);
118+
return $otherType->isGreaterThan($this, $phpVersion);
119119
}
120120

121121
return TrinaryLogic::createMaybe();

src/Type/Traits/ConstantScalarTypeTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ public function equals(Type $type): bool
7878
return $type instanceof self && $this->value === $type->value;
7979
}
8080

81-
public function isSmallerThan(Type $otherType): TrinaryLogic
81+
public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
8282
{
8383
if ($otherType instanceof ConstantScalarType) {
8484
return TrinaryLogic::createFromBoolean($this->value < $otherType->getValue());
8585
}
8686

8787
if ($otherType instanceof CompoundType) {
88-
return $otherType->isGreaterThan($this);
88+
return $otherType->isGreaterThan($this, $phpVersion);
8989
}
9090

9191
return TrinaryLogic::createMaybe();

src/Type/Traits/LateResolvableTypeTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ public function toArrayKey(): Type
367367
return $this->resolve()->toArrayKey();
368368
}
369369

370-
public function isSmallerThan(Type $otherType): TrinaryLogic
370+
public function isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
371371
{
372-
return $this->resolve()->isSmallerThan($otherType);
372+
return $this->resolve()->isSmallerThan($otherType, $phpVersion);
373373
}
374374

375375
public function isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
@@ -539,15 +539,15 @@ public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes):
539539
return $acceptingType->acceptsWithReason($result, $strictTypes);
540540
}
541541

542-
public function isGreaterThan(Type $otherType): TrinaryLogic
542+
public function isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
543543
{
544544
$result = $this->resolve();
545545

546546
if ($result instanceof CompoundType) {
547-
return $result->isGreaterThan($otherType);
547+
return $result->isGreaterThan($otherType, $phpVersion);
548548
}
549549

550-
return $otherType->isSmallerThan($result);
550+
return $otherType->isSmallerThan($result, $phpVersion);
551551
}
552552

553553
public function isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic

0 commit comments

Comments
 (0)