Skip to content

Commit 2082cc3

Browse files
committed
Add missing descriptors for SmallFloatType and EnumType
1 parent 6317ec1 commit 2082cc3

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
"doctrine/annotations": "^2.0",
2424
"doctrine/collections": "^1.6 || ^2.1",
2525
"doctrine/common": "^2.7 || ^3.0",
26-
"doctrine/dbal": "^3.3.8",
26+
"doctrine/dbal": "^3.3.8 || ^4.0",
2727
"doctrine/lexer": "^2.0 || ^3.0",
2828
"doctrine/mongodb-odm": "^2.4.3",
29-
"doctrine/orm": "^2.16.0",
29+
"doctrine/orm": "^2.16.0 || ^3.0",
3030
"doctrine/persistence": "^2.2.1 || ^3.2",
3131
"gedmo/doctrine-extensions": "^3.8",
32-
"nesbot/carbon": "^2.49",
32+
"nesbot/carbon": "^2.49 || ^3.0",
3333
"php-parallel-lint/php-parallel-lint": "^1.2",
3434
"phpstan/phpstan-deprecation-rules": "^2.0.2",
3535
"phpstan/phpstan-phpunit": "^2.0",

extension.neon

+6
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ services:
353353
-
354354
class: PHPStan\Type\Doctrine\Descriptors\DecimalType
355355
tags: [phpstan.doctrine.typeDescriptor]
356+
-
357+
class: PHPStan\Type\Doctrine\Descriptors\EnumType
358+
tags: [phpstan.doctrine.typeDescriptor]
356359
-
357360
class: PHPStan\Type\Doctrine\Descriptors\FloatType
358361
tags: [phpstan.doctrine.typeDescriptor]
@@ -374,6 +377,9 @@ services:
374377
-
375378
class: PHPStan\Type\Doctrine\Descriptors\SimpleArrayType
376379
tags: [phpstan.doctrine.typeDescriptor]
380+
-
381+
class: PHPStan\Type\Doctrine\Descriptors\SmallFloatType
382+
tags: [phpstan.doctrine.typeDescriptor]
377383
-
378384
class: PHPStan\Type\Doctrine\Descriptors\SmallIntType
379385
tags: [phpstan.doctrine.typeDescriptor]
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Descriptors;
4+
5+
use PHPStan\Type\StringType;
6+
use PHPStan\Type\Type;
7+
8+
class EnumType implements DoctrineTypeDescriptor
9+
{
10+
11+
public function getType(): string
12+
{
13+
return \Doctrine\DBAL\Types\EnumType::class;
14+
}
15+
16+
public function getWritableToPropertyType(): Type
17+
{
18+
return new StringType();
19+
}
20+
21+
public function getWritableToDatabaseType(): Type
22+
{
23+
return new StringType();
24+
}
25+
26+
public function getDatabaseInternalType(): Type
27+
{
28+
return new StringType();
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Descriptors;
4+
5+
class SmallFloatType extends FloatType
6+
{
7+
8+
public function getType(): string
9+
{
10+
return \Doctrine\DBAL\Types\SmallFloatType::class;
11+
}
12+
13+
}

src/Type/Doctrine/Query/QueryResultTypeWalker.php

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Type\Doctrine\Query;
44

55
use BackedEnum;
6+
use Doctrine\DBAL\Types\EnumType as DbalEnumType;
67
use Doctrine\DBAL\Types\StringType as DbalStringType;
78
use Doctrine\DBAL\Types\Type as DbalType;
89
use Doctrine\ORM\EntityManagerInterface;
@@ -1235,6 +1236,7 @@ public function walkSelectExpression($selectExpression): string
12351236
if (
12361237
$expr instanceof TypedExpression
12371238
&& !$expr->getReturnType() instanceof DbalStringType // StringType is no-op, so using TypedExpression with that does nothing
1239+
&& !$expr->getReturnType() instanceof DbalEnumType // EnumType is also no-op
12381240
) {
12391241
$dbalTypeName = DbalType::getTypeRegistry()->lookupName($expr->getReturnType());
12401242
$type = TypeCombinator::intersect( // e.g. count is typed as int, but we infer int<0, max>

0 commit comments

Comments
 (0)