Skip to content

Commit 1009ca9

Browse files
Wip
1 parent 0d88669 commit 1009ca9

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.2 || ^8.0",
10-
"phpstan/phpstan": "^1.12"
10+
"phpstan/phpstan": "1.12.6"
1111
},
1212
"conflict": {
1313
"doctrine/collections": "<1.0",

tests/Type/Doctrine/Query/QueryResultTypeWalkerHydrationModeTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Php\PhpVersion;
1212
use PHPStan\Testing\PHPStanTestCase;
1313
use PHPStan\Type\Accessory\AccessoryArrayListType;
14+
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
1415
use PHPStan\Type\Accessory\AccessoryNumericStringType;
1516
use PHPStan\Type\ArrayType;
1617
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
@@ -308,12 +309,17 @@ private static function list(Type $values): Type
308309
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), $values));
309310
}
310311

311-
private static function numericString(): Type
312+
private static function numericString(bool $lowercase = false): Type
312313
{
313-
return new IntersectionType([
314+
$types = [
314315
new StringType(),
315316
new AccessoryNumericStringType(),
316-
]);
317+
];
318+
if ($lowercase) {
319+
$types[] = new AccessoryLowercaseStringType();
320+
}
321+
322+
return new IntersectionType($types);
317323
}
318324

319325
/**

tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\Php\PhpVersion;
1616
use PHPStan\Testing\PHPStanTestCase;
1717
use PHPStan\Type\Accessory\AccessoryArrayListType;
18+
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
1819
use PHPStan\Type\Accessory\AccessoryNumericStringType;
1920
use PHPStan\Type\ArrayType;
2021
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
@@ -376,7 +377,7 @@ public function getTestData(): iterable
376377
]),
377378
$this->constantArray([
378379
[new ConstantIntegerType(0), new ObjectType(One::class)],
379-
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString()],
380+
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString(true)],
380381
[new ConstantStringType('intColumn'), new IntegerType()],
381382
])
382383
),
@@ -398,7 +399,7 @@ public function getTestData(): iterable
398399
]),
399400
$this->constantArray([
400401
[new ConstantIntegerType(0), new ObjectType(Many::class)],
401-
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString()],
402+
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString(true)],
402403
[new ConstantStringType('intColumn'), new IntegerType()],
403404
])
404405
),
@@ -419,7 +420,7 @@ public function getTestData(): iterable
419420
]),
420421
$this->constantArray([
421422
[new ConstantStringType('one'), new ObjectType(One::class)],
422-
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString()],
423+
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString(true)],
423424
[new ConstantStringType('intColumn'), new IntegerType()],
424425
])
425426
),
@@ -529,7 +530,7 @@ public function getTestData(): iterable
529530
yield 'just root entity and scalars' => [
530531
$this->constantArray([
531532
[new ConstantIntegerType(0), new ObjectType(One::class)],
532-
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString()],
533+
[new ConstantStringType('id'), $hasDbal4 ? new IntegerType() : $this->numericString(true)],
533534
]),
534535
'
535536
SELECT o, o.id
@@ -1474,7 +1475,7 @@ public function getTestData(): iterable
14741475
$this->constantArray([
14751476
[new ConstantStringType('minusInt'), $this->stringifies() ? new ConstantStringType('-1') : new ConstantIntegerType(-1)],
14761477
[new ConstantStringType('minusFloat'), $this->stringifies() ? $this->numericString() : new ConstantFloatType(-0.1)],
1477-
[new ConstantStringType('minusIntRange'), $this->stringifies() ? $this->numericString() : IntegerRangeType::fromInterval(null, 0)],
1478+
[new ConstantStringType('minusIntRange'), $this->stringifies() ? $this->numericString(true) : IntegerRangeType::fromInterval(null, 0)],
14781479
]),
14791480
'
14801481
SELECT -1 as minusInt,
@@ -1523,7 +1524,7 @@ private function yieldConditionalDataset(): iterable
15231524
],
15241525
[
15251526
new ConstantIntegerType(3),
1526-
$this->numericString(),
1527+
$this->numericString(true),
15271528
],
15281529
]),
15291530
'
@@ -1622,12 +1623,17 @@ private function constantArray(array $elements): Type
16221623
return $builder->getArray();
16231624
}
16241625

1625-
private function numericString(): Type
1626+
private function numericString(bool $lowercase = false): Type
16261627
{
1627-
return new IntersectionType([
1628+
$types = [
16281629
new StringType(),
16291630
new AccessoryNumericStringType(),
1630-
]);
1631+
];
1632+
if ($lowercase) {
1633+
$types[] = new AccessoryLowercaseStringType();
1634+
}
1635+
1636+
return new IntersectionType($types);
16311637
}
16321638

16331639
private function uint(): Type
@@ -1673,14 +1679,14 @@ private function stringifies(): bool
16731679
private function intOrStringified(): Type
16741680
{
16751681
return $this->stringifies()
1676-
? $this->numericString()
1682+
? $this->numericString(true)
16771683
: new IntegerType();
16781684
}
16791685

16801686
private function uintOrStringified(): Type
16811687
{
16821688
return $this->stringifies()
1683-
? $this->numericString()
1689+
? $this->numericString(true)
16841690
: $this->uint();
16851691
}
16861692

0 commit comments

Comments
 (0)