Skip to content

Commit e5d9646

Browse files
committed
DecimalType - writes numeric-string
1 parent f93f5a8 commit e5d9646

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Type/Doctrine/Descriptors/DecimalType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use PHPStan\Type\Accessory\AccessoryNumericStringType;
56
use PHPStan\Type\Type;
67
use PHPStan\Type\TypeCombinator;
78

@@ -15,7 +16,7 @@ public function getType(): string
1516

1617
public function getWritableToPropertyType(): Type
1718
{
18-
return new \PHPStan\Type\StringType();
19+
return TypeCombinator::intersect(new \PHPStan\Type\StringType(), new AccessoryNumericStringType());
1920
}
2021

2122
public function getWritableToDatabaseType(): Type

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPStan\Type\Doctrine\Descriptors\DateTimeImmutableType;
1414
use PHPStan\Type\Doctrine\Descriptors\DateTimeType;
1515
use PHPStan\Type\Doctrine\Descriptors\DateType;
16+
use PHPStan\Type\Doctrine\Descriptors\DecimalType;
1617
use PHPStan\Type\Doctrine\Descriptors\IntegerType;
1718
use PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor;
1819
use PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor;
@@ -48,6 +49,7 @@ protected function getRule(): Rule
4849
new DateType(),
4950
new UuidTypeDescriptor(UuidType::class),
5051
new ArrayType(),
52+
new DecimalType(),
5153
]),
5254
true
5355
);

tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,22 @@ class MyBrokenEntity extends MyBrokenSuperclass
101101
*/
102102
private $arrayOfIntegersOrNull;
103103

104+
/**
105+
* @ORM\Column(type="decimal")
106+
* @var int|float|numeric-string
107+
*/
108+
private $decimal;
109+
110+
/**
111+
* @ORM\Column(type="decimal")
112+
* @var int|float|string
113+
*/
114+
private $decimalWithString;
115+
116+
/**
117+
* @ORM\Column(type="decimal")
118+
* @var string
119+
*/
120+
private $decimalWithString2;
121+
104122
}

0 commit comments

Comments
 (0)