Skip to content

Commit 026b814

Browse files
[make:entity] Fix error while making blob in entity (#1176)
Co-authored-by: Jesse Rushlow <jr@rushlow.dev>
1 parent ea972b4 commit 026b814

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/Util/ClassSourceManipulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function addGetter(string $propertyName, $returnType, bool $isReturnTypeN
266266
$this->addCustomGetter($propertyName, $methodName, $returnType, $isReturnTypeNullable, $commentLines);
267267
}
268268

269-
public function addSetter(string $propertyName, string $type, bool $isNullable, array $commentLines = []): void
269+
public function addSetter(string $propertyName, ?string $type, bool $isNullable, array $commentLines = []): void
270270
{
271271
$builder = $this->createSetterNodeBuilder($propertyName, $type, $isNullable, $commentLines);
272272
$builder->addStmt(

tests/Util/ClassSourceManipulatorTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function getAddGetterTests(): \Generator
127127
/**
128128
* @dataProvider getAddSetterTests
129129
*/
130-
public function testAddSetter(string $sourceFilename, string $propertyName, string $type, bool $isNullable, array $commentLines, $expectedSourceFilename): void
130+
public function testAddSetter(string $sourceFilename, string $propertyName, ?string $type, bool $isNullable, array $commentLines, $expectedSourceFilename): void
131131
{
132132
$source = file_get_contents(__DIR__.'/fixtures/source/'.$sourceFilename);
133133
$expectedSource = file_get_contents(__DIR__.'/fixtures/add_setter/'.$expectedSourceFilename);
@@ -169,6 +169,15 @@ public function getAddSetterTests(): \Generator
169169
[],
170170
'User_empty.php',
171171
];
172+
173+
yield 'setter_null_type' => [
174+
'User_simple.php',
175+
'fooProp',
176+
null,
177+
false,
178+
[],
179+
'User_simple_null_type.php',
180+
];
172181
}
173182

174183
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
#[ORM\Entity]
8+
class User
9+
{
10+
#[ORM\Id]
11+
#[ORM\GeneratedValue]
12+
#[ORM\Column()]
13+
private ?int $id = null;
14+
15+
public function getId(): ?int
16+
{
17+
return $this->id;
18+
}
19+
20+
public function setFooProp($fooProp): self
21+
{
22+
$this->fooProp = $fooProp;
23+
24+
return $this;
25+
}
26+
}

0 commit comments

Comments
 (0)