Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.12"
"phpstan/phpstan": "^1.12.6"
},
"conflict": {
"doctrine/collections": "<1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Php\PhpVersion;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
Expand Down Expand Up @@ -308,12 +309,17 @@ private static function list(Type $values): Type
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), $values));
}

private static function numericString(): Type
private static function numericString(bool $lowercase = false): Type
{
return new IntersectionType([
$types = [
new StringType(),
new AccessoryNumericStringType(),
]);
];
if ($lowercase) {
$types[] = new AccessoryLowercaseStringType();
}

return new IntersectionType($types);
}

/**
Expand Down
18 changes: 12 additions & 6 deletions tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPStan\Php\PhpVersion;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
Expand Down Expand Up @@ -1474,7 +1475,7 @@ public function getTestData(): iterable
$this->constantArray([
[new ConstantStringType('minusInt'), $this->stringifies() ? new ConstantStringType('-1') : new ConstantIntegerType(-1)],
[new ConstantStringType('minusFloat'), $this->stringifies() ? $this->numericString() : new ConstantFloatType(-0.1)],
[new ConstantStringType('minusIntRange'), $this->stringifies() ? $this->numericString() : IntegerRangeType::fromInterval(null, 0)],
[new ConstantStringType('minusIntRange'), $this->stringifies() ? $this->numericString(true) : IntegerRangeType::fromInterval(null, 0)],
]),
'
SELECT -1 as minusInt,
Expand Down Expand Up @@ -1622,12 +1623,17 @@ private function constantArray(array $elements): Type
return $builder->getArray();
}

private function numericString(): Type
private function numericString(bool $lowercase = false): Type
{
return new IntersectionType([
$types = [
new StringType(),
new AccessoryNumericStringType(),
]);
];
if ($lowercase) {
$types[] = new AccessoryLowercaseStringType();
}

return new IntersectionType($types);
}

private function uint(): Type
Expand Down Expand Up @@ -1673,14 +1679,14 @@ private function stringifies(): bool
private function intOrStringified(): Type
{
return $this->stringifies()
? $this->numericString()
? $this->numericString(true)
: new IntegerType();
}

private function uintOrStringified(): Type
{
return $this->stringifies()
? $this->numericString()
? $this->numericString(true)
: $this->uint();
}

Expand Down