Skip to content

Use object typehint when generating entities #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,8 @@ private function getEntityTypeHint($doctrineType): ?string
return '\\'.\DateInterval::class;

case 'object':
return 'object';

case 'binary':
case 'blob':
default:
Expand Down
9 changes: 9 additions & 0 deletions tests/Util/ClassSourceManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ public function getAddEntityFieldTests(): \Generator
],
'User_simple_prop_zero.php',
];

yield 'entity_add_object' => [
'User_simple.php',
'someObject',
[
'type' => 'object',
],
'User_simple_object.php',
];
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/Util/fixtures/add_entity_field/User_simple_object.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class User
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;

#[ORM\Column(type: 'object')]
private $someObject;

public function getId(): ?int
{
return $this->id;
}

public function getSomeObject(): ?object
{
return $this->someObject;
}

public function setSomeObject(object $someObject): self
{
$this->someObject = $someObject;

return $this;
}
}
40 changes: 40 additions & 0 deletions tests/Util/fixtures/add_entity_field/legacy/User_simple_object.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
*/
class User
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\Column(type="object")
*/
private $someObject;

public function getId(): ?int
{
return $this->id;
}

public function getSomeObject(): ?object
{
return $this->someObject;
}

public function setSomeObject(object $someObject): self
{
$this->someObject = $someObject;

return $this;
}
}