Skip to content

Commit 31c1a46

Browse files
committed
Doctrine decimal type getters and setters now always use string values
1 parent 5130e54 commit 31c1a46

File tree

5 files changed

+4
-38
lines changed

5 files changed

+4
-38
lines changed

UPGRADE-4.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# UPGRADE FROM 3.x to 4.0
22

3+
## Main
4+
5+
* Doctrine decimal type getters and setters now always use string values
6+
37
## Template
48

59
* When generating getters/setters for a field, the `types` variable passed to the Twig template no longer exists.

templates/Theme/base.php.twig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@
6565
{% endif %}
6666
{% endblock %}
6767

68-
{% block field_hint_decimal %}
69-
{# Decimal Doctrine type is a PHP string but user can give a double value - Remove hint unless hint equals "string" on the property PHP hint #}
70-
{% if phpType and (phpType.__toString() == '?string' or phpType.__toString() == 'string') %}
71-
?string
72-
{% endif %}
73-
{% endblock %}
74-
7568
{% block field_set %}
7669
public function {{ methodName }}({{ (block('field_hint')|spaceless) ? block('field_hint')|spaceless ~ ' ' : '' }}${{ variableName }}): self
7770
{

tests/App/Entity/SubClass.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class SubClass extends MainClass
5757
#[ORM\Column(type: 'decimal', precision: 5, scale: 2)]
5858
protected ?string $decimalField;
5959

60-
#[ORM\Column(type: 'decimal', precision: 5, scale: 2)]
61-
protected $decimalFieldWithoutHint;
62-
6360
#[ORM\Column(type: 'datetime')]
6461
protected ?\DateTime $dateField = null;
6562

tests/App/GeneratedEntity/SubClass.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ class SubClass extends MainClass
5858
#[ORM\Column(type: 'decimal', precision: 5, scale: 2)]
5959
protected ?string $decimalField;
6060

61-
#[ORM\Column(type: 'decimal', precision: 5, scale: 2)]
62-
protected $decimalFieldWithoutHint;
63-
6461
#[ORM\Column(type: 'datetime')]
6562
protected ?\DateTime $dateField = null;
6663

@@ -132,18 +129,6 @@ public function getDecimalField(): ?string
132129
return $this->decimalField;
133130
}
134131

135-
public function setDecimalFieldWithoutHint($decimalFieldWithoutHint): self
136-
{
137-
$this->decimalFieldWithoutHint = $decimalFieldWithoutHint;
138-
139-
return $this;
140-
}
141-
142-
public function getDecimalFieldWithoutHint()
143-
{
144-
return $this->decimalFieldWithoutHint;
145-
}
146-
147132
public function setDateField(?\DateTime $dateField): self
148133
{
149134
$this->dateField = $dateField;

tests/GeneratedEntityTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,6 @@ public function testDecimalField(): void
116116
$this->assertSame('0.55', $subClass->getDecimalField());
117117
}
118118

119-
public function testDecimalFieldWithoutHint(): void
120-
{
121-
$subClass = $this->createSubClass(2);
122-
$this->assertSame(0.65, $subClass->getDecimalFieldWithoutHint());
123-
$this->em->flush();
124-
$this->em->clear();
125-
126-
$subClass = $this->em->getRepository(SubClass::class)->find(2);
127-
$this->assertSame('0.65', $subClass->getDecimalFieldWithoutHint());
128-
}
129-
130119
public function testDateField(): void
131120
{
132121
$subClass = $this->createSubClass(2);
@@ -178,7 +167,6 @@ public static function getTestSetNullFieldProvider(): array
178167
['setName', 'getName'],
179168
['setNameWithoutHint', 'getNameWithoutHint'],
180169
['setDecimalField', 'getDecimalField'],
181-
['setDecimalFieldWithoutHint', 'getDecimalFieldWithoutHint'],
182170
['setDateField', 'getDateField'],
183171
['setBooleanField', 'getBooleanField'],
184172
['setTextField', 'getTextField'],
@@ -564,7 +552,6 @@ protected function createSubClass(int $id, ?Initializer1 $firstInitializer = nul
564552
->setFirstInitializer($firstInitializer)
565553
->setSecondInitializer($secondInitializer)
566554
->setDecimalField('0.55')
567-
->setDecimalFieldWithoutHint(0.65) // Give a double - Doctrine will return string
568555
->setDateField(new \DateTime('2020-01-01 00:00:00'))
569556
->setBooleanField(true)
570557
->setTextField('Text '.$id)

0 commit comments

Comments
 (0)