Skip to content

Commit 8ba587e

Browse files
More
1 parent d893ba0 commit 8ba587e

12 files changed

+64
-60
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPStan\Node\Expr\AlwaysRememberedExpr;
2323
use PHPStan\Node\IssetExpr;
2424
use PHPStan\Node\Printer\ExprPrinter;
25+
use PHPStan\Php\PhpVersion;
2526
use PHPStan\Reflection\Assertions;
2627
use PHPStan\Reflection\ParametersAcceptor;
2728
use PHPStan\Reflection\ParametersAcceptorSelector;
@@ -100,6 +101,7 @@ final class TypeSpecifier
100101
public function __construct(
101102
private ExprPrinter $exprPrinter,
102103
private ReflectionProvider $reflectionProvider,
104+
private PhpVersion $phpVersion,
103105
private array $functionTypeSpecifyingExtensions,
104106
private array $methodTypeSpecifyingExtensions,
105107
private array $staticMethodTypeSpecifyingExtensions,
@@ -406,7 +408,7 @@ public function specifyTypesInCondition(
406408
$result = $result->unionWith(
407409
$this->create(
408410
$expr->left,
409-
$orEqual ? $rightType->getSmallerOrEqualType() : $rightType->getSmallerType(),
411+
$orEqual ? $rightType->getSmallerOrEqualType($this->phpVersion) : $rightType->getSmallerType($this->phpVersion),
410412
TypeSpecifierContext::createTruthy(),
411413
$scope,
412414
)->setRootExpr($expr),
@@ -416,7 +418,7 @@ public function specifyTypesInCondition(
416418
$result = $result->unionWith(
417419
$this->create(
418420
$expr->right,
419-
$orEqual ? $leftType->getGreaterOrEqualType() : $leftType->getGreaterType(),
421+
$orEqual ? $leftType->getGreaterOrEqualType($this->phpVersion) : $leftType->getGreaterType($this->phpVersion),
420422
TypeSpecifierContext::createTruthy(),
421423
$scope,
422424
)->setRootExpr($expr),
@@ -427,7 +429,7 @@ public function specifyTypesInCondition(
427429
$result = $result->unionWith(
428430
$this->create(
429431
$expr->left,
430-
$orEqual ? $rightType->getGreaterType() : $rightType->getGreaterOrEqualType(),
432+
$orEqual ? $rightType->getGreaterType($this->phpVersion) : $rightType->getGreaterOrEqualType($this->phpVersion),
431433
TypeSpecifierContext::createTruthy(),
432434
$scope,
433435
)->setRootExpr($expr),
@@ -437,7 +439,7 @@ public function specifyTypesInCondition(
437439
$result = $result->unionWith(
438440
$this->create(
439441
$expr->right,
440-
$orEqual ? $leftType->getSmallerType() : $leftType->getSmallerOrEqualType(),
442+
$orEqual ? $leftType->getSmallerType($this->phpVersion) : $leftType->getSmallerOrEqualType($this->phpVersion),
441443
TypeSpecifierContext::createTruthy(),
442444
$scope,
443445
)->setRootExpr($expr),

src/Type/Constant/ConstantBooleanType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@ public function describe(VerbosityLevel $level): string
4040
return $this->value ? 'true' : 'false';
4141
}
4242

43-
public function getSmallerType(): Type
43+
public function getSmallerType(PhpVersion $phpVersion): Type
4444
{
4545
if ($this->value) {
4646
return StaticTypeFactory::falsey();
4747
}
4848
return new NeverType();
4949
}
5050

51-
public function getSmallerOrEqualType(): Type
51+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
5252
{
5353
if ($this->value) {
5454
return new MixedType();
5555
}
5656
return StaticTypeFactory::falsey();
5757
}
5858

59-
public function getGreaterType(): Type
59+
public function getGreaterType(PhpVersion $phpVersion): Type
6060
{
6161
if ($this->value) {
6262
return new NeverType();
6363
}
6464
return StaticTypeFactory::truthy();
6565
}
6666

67-
public function getGreaterOrEqualType(): Type
67+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
6868
{
6969
if ($this->value) {
7070
return StaticTypeFactory::truthy();

src/Type/Constant/ConstantStringType.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Nette\Utils\Strings;
77
use PhpParser\Node\Name;
88
use PHPStan\Analyser\OutOfClassScope;
9+
use PHPStan\Php\PhpVersion;
910
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
1011
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
1112
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
@@ -461,7 +462,7 @@ public function generalize(GeneralizePrecision $precision): Type
461462
return new StringType();
462463
}
463464

464-
public function getSmallerType(): Type
465+
public function getSmallerType(PhpVersion $phpVersion): Type
465466
{
466467
$subtractedTypes = [
467468
new ConstantBooleanType(true),
@@ -480,7 +481,7 @@ public function getSmallerType(): Type
480481
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
481482
}
482483

483-
public function getSmallerOrEqualType(): Type
484+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
484485
{
485486
$subtractedTypes = [
486487
IntegerRangeType::createAllGreaterThan((float) $this->value),
@@ -493,7 +494,7 @@ public function getSmallerOrEqualType(): Type
493494
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
494495
}
495496

496-
public function getGreaterType(): Type
497+
public function getGreaterType(PhpVersion $phpVersion): Type
497498
{
498499
$subtractedTypes = [
499500
new ConstantBooleanType(false),
@@ -507,7 +508,7 @@ public function getGreaterType(): Type
507508
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
508509
}
509510

510-
public function getGreaterOrEqualType(): Type
511+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
511512
{
512513
$subtractedTypes = [
513514
IntegerRangeType::createAllSmallerThan((float) $this->value),

src/Type/IntegerRangeType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): T
376376
return TrinaryLogic::extremeIdentity($minIsSmaller, $maxIsSmaller);
377377
}
378378

379-
public function getSmallerType(): Type
379+
public function getSmallerType(PhpVersion $phpVersion): Type
380380
{
381381
$subtractedTypes = [
382382
new ConstantBooleanType(true),
@@ -389,7 +389,7 @@ public function getSmallerType(): Type
389389
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
390390
}
391391

392-
public function getSmallerOrEqualType(): Type
392+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
393393
{
394394
$subtractedTypes = [];
395395

@@ -400,7 +400,7 @@ public function getSmallerOrEqualType(): Type
400400
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
401401
}
402402

403-
public function getGreaterType(): Type
403+
public function getGreaterType(PhpVersion $phpVersion): Type
404404
{
405405
$subtractedTypes = [
406406
new NullType(),
@@ -418,7 +418,7 @@ public function getGreaterType(): Type
418418
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
419419
}
420420

421-
public function getGreaterOrEqualType(): Type
421+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
422422
{
423423
$subtractedTypes = [];
424424

src/Type/IntersectionType.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -886,24 +886,24 @@ public function isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): T
886886
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $otherType->isSmallerThanOrEqual($type, $phpVersion));
887887
}
888888

889-
public function getSmallerType(): Type
889+
public function getSmallerType(PhpVersion $phpVersion): Type
890890
{
891-
return $this->intersectTypes(static fn (Type $type): Type => $type->getSmallerType());
891+
return $this->intersectTypes(static fn (Type $type): Type => $type->getSmallerType($phpVersion));
892892
}
893893

894-
public function getSmallerOrEqualType(): Type
894+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
895895
{
896-
return $this->intersectTypes(static fn (Type $type): Type => $type->getSmallerOrEqualType());
896+
return $this->intersectTypes(static fn (Type $type): Type => $type->getSmallerOrEqualType($phpVersion));
897897
}
898898

899-
public function getGreaterType(): Type
899+
public function getGreaterType(PhpVersion $phpVersion): Type
900900
{
901-
return $this->intersectTypes(static fn (Type $type): Type => $type->getGreaterType());
901+
return $this->intersectTypes(static fn (Type $type): Type => $type->getGreaterType($phpVersion));
902902
}
903903

904-
public function getGreaterOrEqualType(): Type
904+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
905905
{
906-
return $this->intersectTypes(static fn (Type $type): Type => $type->getGreaterOrEqualType());
906+
return $this->intersectTypes(static fn (Type $type): Type => $type->getGreaterOrEqualType($phpVersion));
907907
}
908908

909909
public function toBoolean(): BooleanType

src/Type/NullType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
338338
return new BooleanType();
339339
}
340340

341-
public function getSmallerType(): Type
341+
public function getSmallerType(PhpVersion $phpVersion): Type
342342
{
343343
return new NeverType();
344344
}
345345

346-
public function getSmallerOrEqualType(): Type
346+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
347347
{
348348
// All falsey types except '0'
349349
return new UnionType([
@@ -356,7 +356,7 @@ public function getSmallerOrEqualType(): Type
356356
]);
357357
}
358358

359-
public function getGreaterType(): Type
359+
public function getGreaterType(PhpVersion $phpVersion): Type
360360
{
361361
// All truthy types, but also '0'
362362
return new MixedType(false, new UnionType([
@@ -369,7 +369,7 @@ public function getGreaterType(): Type
369369
]));
370370
}
371371

372-
public function getGreaterOrEqualType(): Type
372+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
373373
{
374374
return new MixedType();
375375
}

src/Type/Traits/ConstantNumericComparisonTypeTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Type\Traits;
44

5+
use PHPStan\Php\PhpVersion;
56
use PHPStan\Type\Constant\ConstantBooleanType;
67
use PHPStan\Type\Constant\ConstantFloatType;
78
use PHPStan\Type\IntegerRangeType;
@@ -13,7 +14,7 @@
1314
trait ConstantNumericComparisonTypeTrait
1415
{
1516

16-
public function getSmallerType(): Type
17+
public function getSmallerType(PhpVersion $phpVersion): Type
1718
{
1819
$subtractedTypes = [
1920
new ConstantBooleanType(true),
@@ -29,7 +30,7 @@ public function getSmallerType(): Type
2930
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
3031
}
3132

32-
public function getSmallerOrEqualType(): Type
33+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
3334
{
3435
$subtractedTypes = [
3536
IntegerRangeType::createAllGreaterThan($this->value),
@@ -43,7 +44,7 @@ public function getSmallerOrEqualType(): Type
4344
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
4445
}
4546

46-
public function getGreaterType(): Type
47+
public function getGreaterType(PhpVersion $phpVersion): Type
4748
{
4849
$subtractedTypes = [
4950
new NullType(),
@@ -59,7 +60,7 @@ public function getGreaterType(): Type
5960
return TypeCombinator::remove(new MixedType(), TypeCombinator::union(...$subtractedTypes));
6061
}
6162

62-
public function getGreaterOrEqualType(): Type
63+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
6364
{
6465
$subtractedTypes = [
6566
IntegerRangeType::createAllSmallerThan($this->value),

src/Type/Traits/LateResolvableTypeTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,24 +482,24 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
482482
return new BooleanType();
483483
}
484484

485-
public function getSmallerType(): Type
485+
public function getSmallerType(PhpVersion $phpVersion): Type
486486
{
487-
return $this->resolve()->getSmallerType();
487+
return $this->resolve()->getSmallerType($phpVersion);
488488
}
489489

490-
public function getSmallerOrEqualType(): Type
490+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
491491
{
492-
return $this->resolve()->getSmallerOrEqualType();
492+
return $this->resolve()->getSmallerOrEqualType($phpVersion);
493493
}
494494

495-
public function getGreaterType(): Type
495+
public function getGreaterType(PhpVersion $phpVersion): Type
496496
{
497-
return $this->resolve()->getGreaterType();
497+
return $this->resolve()->getGreaterType($phpVersion);
498498
}
499499

500-
public function getGreaterOrEqualType(): Type
500+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
501501
{
502-
return $this->resolve()->getGreaterOrEqualType();
502+
return $this->resolve()->getGreaterOrEqualType($phpVersion);
503503
}
504504

505505
public function inferTemplateTypes(Type $receivedType): TemplateTypeMap

src/Type/Traits/UndecidedComparisonTypeTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ public function isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): T
2020
return TrinaryLogic::createMaybe();
2121
}
2222

23-
public function getSmallerType(): Type
23+
public function getSmallerType(PhpVersion $phpVersion): Type
2424
{
2525
return new MixedType();
2626
}
2727

28-
public function getSmallerOrEqualType(): Type
28+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
2929
{
3030
return new MixedType();
3131
}
3232

33-
public function getGreaterType(): Type
33+
public function getGreaterType(PhpVersion $phpVersion): Type
3434
{
3535
return new MixedType();
3636
}
3737

38-
public function getGreaterOrEqualType(): Type
38+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
3939
{
4040
return new MixedType();
4141
}

src/Type/Type.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ public function isScalar(): TrinaryLogic;
269269

270270
public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType;
271271

272-
public function getSmallerType(): Type;
272+
public function getSmallerType(PhpVersion $phpVersion): Type;
273273

274-
public function getSmallerOrEqualType(): Type;
274+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type;
275275

276-
public function getGreaterType(): Type;
276+
public function getGreaterType(PhpVersion $phpVersion): Type;
277277

278-
public function getGreaterOrEqualType(): Type;
278+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type;
279279

280280
/**
281281
* Returns actual template type for a given object.

src/Type/UnionType.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -843,24 +843,24 @@ public function isInteger(): TrinaryLogic
843843
return $this->notBenevolentUnionResults(static fn (Type $type): TrinaryLogic => $type->isInteger());
844844
}
845845

846-
public function getSmallerType(): Type
846+
public function getSmallerType(PhpVersion $phpVersion): Type
847847
{
848-
return $this->unionTypes(static fn (Type $type): Type => $type->getSmallerType());
848+
return $this->unionTypes(static fn (Type $type): Type => $type->getSmallerType($phpVersion));
849849
}
850850

851-
public function getSmallerOrEqualType(): Type
851+
public function getSmallerOrEqualType(PhpVersion $phpVersion): Type
852852
{
853-
return $this->unionTypes(static fn (Type $type): Type => $type->getSmallerOrEqualType());
853+
return $this->unionTypes(static fn (Type $type): Type => $type->getSmallerOrEqualType($phpVersion));
854854
}
855855

856-
public function getGreaterType(): Type
856+
public function getGreaterType(PhpVersion $phpVersion): Type
857857
{
858-
return $this->unionTypes(static fn (Type $type): Type => $type->getGreaterType());
858+
return $this->unionTypes(static fn (Type $type): Type => $type->getGreaterType($phpVersion));
859859
}
860860

861-
public function getGreaterOrEqualType(): Type
861+
public function getGreaterOrEqualType(PhpVersion $phpVersion): Type
862862
{
863-
return $this->unionTypes(static fn (Type $type): Type => $type->getGreaterOrEqualType());
863+
return $this->unionTypes(static fn (Type $type): Type => $type->getGreaterOrEqualType($phpVersion));
864864
}
865865

866866
public function isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic

0 commit comments

Comments
 (0)