Skip to content

Commit 1147835

Browse files
committed
Use Doctrine Types in entities
1 parent bf70bfe commit 1147835

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

src/Entity/Comment.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace App\Entity;
1313

14+
use Doctrine\DBAL\Types\Types;
1415
use Doctrine\ORM\Mapping as ORM;
1516
use function Symfony\Component\String\u;
1617
use Symfony\Component\Validator\Constraints as Assert;
@@ -31,19 +32,19 @@ class Comment
3132
{
3233
#[ORM\Id]
3334
#[ORM\GeneratedValue]
34-
#[ORM\Column(type: 'integer')]
35+
#[ORM\Column(type: Types::INTEGER)]
3536
private ?int $id = null;
3637

3738
#[ORM\ManyToOne(targetEntity: Post::class, inversedBy: 'comments')]
3839
#[ORM\JoinColumn(nullable: false)]
3940
private ?Post $post = null;
4041

41-
#[ORM\Column(type: 'text')]
42+
#[ORM\Column(type: Types::TEXT)]
4243
#[Assert\NotBlank(message: 'comment.blank')]
4344
#[Assert\Length(min: 5, minMessage: 'comment.too_short', max: 10000, maxMessage: 'comment.too_long')]
4445
private ?string $content = null;
4546

46-
#[ORM\Column(type: 'datetime')]
47+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
4748
private \DateTime $publishedAt;
4849

4950
#[ORM\ManyToOne(targetEntity: User::class)]

src/Entity/Post.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Repository\PostRepository;
1515
use Doctrine\Common\Collections\ArrayCollection;
1616
use Doctrine\Common\Collections\Collection;
17+
use Doctrine\DBAL\Types\Types;
1718
use Doctrine\ORM\Mapping as ORM;
1819
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
1920
use Symfony\Component\Validator\Constraints as Assert;
@@ -37,27 +38,27 @@ class Post
3738
{
3839
#[ORM\Id]
3940
#[ORM\GeneratedValue]
40-
#[ORM\Column(type: 'integer')]
41+
#[ORM\Column(type: Types::INTEGER)]
4142
private ?int $id = null;
4243

43-
#[ORM\Column(type: 'string')]
44+
#[ORM\Column(type: Types::STRING)]
4445
#[Assert\NotBlank]
4546
private ?string $title = null;
4647

47-
#[ORM\Column(type: 'string')]
48+
#[ORM\Column(type: Types::STRING)]
4849
private ?string $slug = null;
4950

50-
#[ORM\Column(type: 'string')]
51+
#[ORM\Column(type: Types::STRING)]
5152
#[Assert\NotBlank(message: 'post.blank_summary')]
5253
#[Assert\Length(max: 255)]
5354
private ?string $summary = null;
5455

55-
#[ORM\Column(type: 'text')]
56+
#[ORM\Column(type: Types::TEXT)]
5657
#[Assert\NotBlank(message: 'post.blank_content')]
5758
#[Assert\Length(min: 10, minMessage: 'post.too_short_content')]
5859
private ?string $content = null;
5960

60-
#[ORM\Column(type: 'datetime')]
61+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
6162
private \DateTime $publishedAt;
6263

6364
#[ORM\ManyToOne(targetEntity: User::class)]

src/Entity/Tag.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace App\Entity;
1313

14+
use Doctrine\DBAL\Types\Types;
1415
use Doctrine\ORM\Mapping as ORM;
1516

1617
/**
@@ -26,10 +27,10 @@ class Tag implements \JsonSerializable
2627
{
2728
#[ORM\Id]
2829
#[ORM\GeneratedValue]
29-
#[ORM\Column(type: 'integer')]
30+
#[ORM\Column(type: Types::INTEGER)]
3031
private ?int $id = null;
3132

32-
#[ORM\Column(type: 'string', unique: true)]
33+
#[ORM\Column(type: Types::STRING, unique: true)]
3334
private readonly string $name;
3435

3536
public function __construct(string $name)

src/Entity/User.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace App\Entity;
1313

1414
use App\Repository\UserRepository;
15+
use Doctrine\DBAL\Types\Types;
1516
use Doctrine\ORM\Mapping as ORM;
1617
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
1718
use Symfony\Component\Security\Core\User\UserInterface;
@@ -33,26 +34,26 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
3334
{
3435
#[ORM\Id]
3536
#[ORM\GeneratedValue]
36-
#[ORM\Column(type: 'integer')]
37+
#[ORM\Column(type: Types::INTEGER)]
3738
private ?int $id = null;
3839

39-
#[ORM\Column(type: 'string')]
40+
#[ORM\Column(type: Types::STRING)]
4041
#[Assert\NotBlank]
4142
private ?string $fullName = null;
4243

43-
#[ORM\Column(type: 'string', unique: true)]
44+
#[ORM\Column(type: Types::STRING, unique: true)]
4445
#[Assert\NotBlank]
4546
#[Assert\Length(min: 2, max: 50)]
4647
private ?string $username = null;
4748

48-
#[ORM\Column(type: 'string', unique: true)]
49+
#[ORM\Column(type: Types::STRING, unique: true)]
4950
#[Assert\Email]
5051
private ?string $email = null;
5152

52-
#[ORM\Column(type: 'string')]
53+
#[ORM\Column(type: Types::STRING)]
5354
private ?string $password = null;
5455

55-
#[ORM\Column(type: 'json')]
56+
#[ORM\Column(type: Types::JSON)]
5657
private array $roles = [];
5758

5859
public function getId(): ?int

0 commit comments

Comments
 (0)