Skip to content

Commit 2e8b2b6

Browse files
committed
Add missing descriptors for SmallFloatType and EnumType
1 parent 6317ec1 commit 2e8b2b6

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed

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]

phpstan-baseline-dbal-4.neon

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Class Doctrine\\DBAL\\Types\\EnumType not found\.$#'
5+
identifier: class.notFound
6+
count: 1
7+
path: src/Type/Doctrine/Descriptors/EnumType.php
8+
9+
-
10+
message: '#^Method PHPStan\\Type\\Doctrine\\Descriptors\\EnumType\:\:getType\(\) should return class\-string\<Doctrine\\DBAL\\Types\\Type\> but returns string\.$#'
11+
identifier: return.type
12+
count: 1
13+
path: src/Type/Doctrine/Descriptors/EnumType.php
14+
15+
-
16+
message: '#^Class Doctrine\\DBAL\\Types\\SmallFloatType not found\.$#'
17+
identifier: class.notFound
18+
count: 1
19+
path: src/Type/Doctrine/Descriptors/SmallFloatType.php
20+
21+
-
22+
message: '#^Method PHPStan\\Type\\Doctrine\\Descriptors\\SmallFloatType\:\:getType\(\) should return class\-string\<Doctrine\\DBAL\\Types\\Type\> but returns string\.$#'
23+
identifier: return.type
24+
count: 1
25+
path: src/Type/Doctrine/Descriptors/SmallFloatType.php
26+
27+
-
28+
message: '#^Class Doctrine\\DBAL\\Types\\EnumType not found\.$#'
29+
identifier: class.notFound
30+
count: 1
31+
path: src/Type/Doctrine/Query/QueryResultTypeWalker.php
32+
33+

phpstan-baseline.neon

+6
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ parameters:
8383
identifier: phpstanApi.classConstant
8484
count: 1
8585
path: tests/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php
86+
87+
-
88+
message: '#^Parameter references internal interface Doctrine\\ORM\\Query\\AST\\Phase2OptimizableConditional in its type\.$#'
89+
identifier: parameter.internalInterface
90+
count: 2
91+
path: src/Type/Doctrine/Query/QueryResultTypeWalker.php

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ includes:
44
- phpstan-baseline.neon
55
- phpstan-baseline-deprecations.neon
66
- phpstan-baseline-dbal-3.neon
7+
- phpstan-baseline-dbal-4.neon
78
- compatibility/orm-3-baseline.php
89
- vendor/phpstan/phpstan-strict-rules/rules.neon
910
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
+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)