Skip to content

Commit 5e4d0b2

Browse files
Support Doctrine NumberType (#754)
1 parent a19c4b2 commit 5e4d0b2

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

extension.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ services:
373373
-
374374
class: PHPStan\Type\Doctrine\Descriptors\JsonType
375375
tags: [phpstan.doctrine.typeDescriptor]
376+
-
377+
class: PHPStan\Type\Doctrine\Descriptors\NumberType
378+
tags: [phpstan.doctrine.typeDescriptor]
376379
-
377380
class: PHPStan\Type\Doctrine\Descriptors\ObjectType
378381
tags: [phpstan.doctrine.typeDescriptor]

phpstan-baseline-dbal-4.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ parameters:
3030
count: 1
3131
path: src/Type/Doctrine/Query/QueryResultTypeWalker.php
3232

33+
-
34+
message: '#^Class Doctrine\\DBAL\\Types\\NumberType not found\.$#'
35+
identifier: class.notFound
36+
count: 1
37+
path: src/Type/Doctrine/Descriptors/NumberType.php
38+
39+
-
40+
message: '#^Method PHPStan\\Type\\Doctrine\\Descriptors\\NumberType\:\:getType\(\) should return class\-string\<Doctrine\\DBAL\\Types\\Type\> but returns string\.$#'
41+
identifier: return.type
42+
count: 1
43+
path: src/Type/Doctrine/Descriptors/NumberType.php
44+
3345
-
3446
rawMessage: '''
3547
Call to method __construct() of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver:
Lines changed: 31 additions & 0 deletions
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\ObjectType;
6+
use PHPStan\Type\Type;
7+
8+
class NumberType implements DoctrineTypeDescriptor
9+
{
10+
11+
public function getType(): string
12+
{
13+
return \Doctrine\DBAL\Types\NumberType::class;
14+
}
15+
16+
public function getWritableToPropertyType(): Type
17+
{
18+
return new ObjectType('BcMath\Number');
19+
}
20+
21+
public function getWritableToDatabaseType(): Type
22+
{
23+
return new ObjectType('BcMath\Number');
24+
}
25+
26+
public function getDatabaseInternalType(): Type
27+
{
28+
return (new ObjectType('BcMath\Number'))->toString();
29+
}
30+
31+
}

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPStan\Type\Doctrine\Descriptors\EnumType;
2222
use PHPStan\Type\Doctrine\Descriptors\IntegerType;
2323
use PHPStan\Type\Doctrine\Descriptors\JsonType;
24+
use PHPStan\Type\Doctrine\Descriptors\NumberType;
2425
use PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor as RamseyUuidTypeDescriptor;
2526
use PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor;
2627
use PHPStan\Type\Doctrine\Descriptors\SimpleArrayType;
@@ -95,6 +96,7 @@ protected function getRule(): Rule
9596
new DecimalType(new DriverDetector()),
9697
new JsonType(),
9798
new IntegerType(),
99+
new NumberType(),
98100
new StringType(),
99101
new SimpleArrayType(),
100102
new EnumType(),

0 commit comments

Comments
 (0)