Skip to content

Commit 2f7cfc4

Browse files
Add native property types to the test app entities
Collection-valued associations are typed with the Collection interface (Doctrine hydrates them as PersistentCollection, so ArrayCollection would fail), and nullable properties get an explicit null default to keep behaving like the untyped properties they replace (e.g. reading the id of a not-yet-persisted entity).
1 parent 8205de9 commit 2f7cfc4

7 files changed

Lines changed: 28 additions & 28 deletions

File tree

tests/Functional/Apps/DefaultApp/src/Entity/Bill.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Bill
1313
#[ORM\Id]
1414
#[ORM\GeneratedValue]
1515
#[ORM\Column(type: 'integer')]
16-
private $id;
16+
private ?int $id = null;
1717

1818
#[ORM\Column(type: 'string', length: 255)]
19-
private $name;
19+
private ?string $name = null;
2020

2121
#[ORM\ManyToMany(targetEntity: Customer::class, inversedBy: 'bills')]
22-
private $customers;
22+
private Collection $customers;
2323

2424
public function __construct()
2525
{

tests/Functional/Apps/DefaultApp/src/Entity/BlogPost.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ class BlogPost
1212
#[ORM\Id]
1313
#[ORM\GeneratedValue]
1414
#[ORM\Column(type: 'integer')]
15-
private $id;
15+
private ?int $id = null;
1616

1717
#[ORM\Column(type: 'string', length: 255)]
18-
private $title;
18+
private ?string $title = null;
1919

2020
#[ORM\Column(type: 'string', length: 255)]
21-
private $slug;
21+
private ?string $slug = null;
2222

2323
#[ORM\Column(type: 'text')]
24-
private $content;
24+
private ?string $content = null;
2525

2626
#[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'blogPosts')]
27-
private $categories;
27+
private Collection $categories;
2828

2929
#[ORM\Column(type: 'datetime_immutable')]
30-
private $createdAt;
30+
private ?\DateTimeInterface $createdAt = null;
3131

3232
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
33-
private $publishedAt;
33+
private ?\DateTimeImmutable $publishedAt = null;
3434

3535
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'blogPosts')]
3636
#[ORM\JoinColumn(nullable: false)]
37-
private $author;
37+
private ?User $author = null;
3838

3939
#[ORM\ManyToOne(targetEntity: User::class)]
4040
private $publisher;

tests/Functional/Apps/DefaultApp/src/Entity/Category.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class Category
1313
#[ORM\Id]
1414
#[ORM\GeneratedValue]
1515
#[ORM\Column(type: 'integer')]
16-
private $id;
16+
private ?int $id = null;
1717

1818
#[Assert\NotBlank]
1919
#[ORM\Column(type: 'string', length: 255)]
20-
private $name;
20+
private ?string $name = null;
2121

2222
#[ORM\Column(type: 'string', length: 255)]
23-
private $slug;
23+
private ?string $slug = null;
2424

2525
#[ORM\ManyToMany(targetEntity: BlogPost::class, mappedBy: 'categories')]
26-
private $blogPosts;
26+
private Collection $blogPosts;
2727

2828
#[ORM\Column(type: 'boolean')]
2929
private bool $active = false;

tests/Functional/Apps/DefaultApp/src/Entity/Customer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Customer
1313
#[ORM\Id]
1414
#[ORM\GeneratedValue]
1515
#[ORM\Column(type: 'integer')]
16-
private $id;
16+
private ?int $id = null;
1717

1818
#[ORM\Column(type: 'string', length: 255)]
19-
private $name;
19+
private ?string $name = null;
2020

2121
#[ORM\ManyToMany(targetEntity: Bill::class, mappedBy: 'customers')]
22-
private $bills;
22+
private Collection $bills;
2323

2424
public function __construct()
2525
{

tests/Functional/Apps/DefaultApp/src/Entity/Page.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class Page
1111
#[ORM\Id]
1212
#[ORM\GeneratedValue]
1313
#[ORM\Column(type: 'integer')]
14-
private $id;
14+
private ?int $id = null;
1515

1616
#[ORM\Column(type: 'string', length: 255)]
17-
private $name;
17+
private ?string $name = null;
1818

1919
#[ORM\ManyToOne(targetEntity: Website::class, inversedBy: 'pages')]
2020
#[ORM\JoinColumn(nullable: false)]
@@ -42,7 +42,7 @@ public function getWebsite()
4242
return $this->website;
4343
}
4444

45-
public function setWebsite(?Website $website)
45+
public function setWebsite(?Website $website): static
4646
{
4747
$this->website = $website;
4848

tests/Functional/Apps/DefaultApp/src/Entity/User.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ class User implements \Stringable
1313
#[ORM\Id]
1414
#[ORM\GeneratedValue]
1515
#[ORM\Column(type: 'integer')]
16-
private $id;
16+
private ?int $id = null;
1717

1818
#[ORM\Column(type: 'string', length: 255)]
19-
private $name;
19+
private ?string $name = null;
2020

2121
#[ORM\Column(type: 'string', length: 255)]
22-
private $email;
22+
private ?string $email = null;
2323

2424
#[ORM\OneToMany(targetEntity: BlogPost::class, mappedBy: 'author', orphanRemoval: true)]
25-
private $blogPosts;
25+
private Collection $blogPosts;
2626

2727
public function __construct()
2828
{

tests/Functional/Apps/DefaultApp/src/Entity/Website.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Website implements \Stringable
1313
#[ORM\Id]
1414
#[ORM\GeneratedValue]
1515
#[ORM\Column(type: 'integer')]
16-
private $id;
16+
private ?int $id = null;
1717

1818
#[ORM\Column(type: 'string', length: 255)]
19-
private $name;
19+
private ?string $name = null;
2020

2121
#[ORM\OneToMany(targetEntity: Page::class, mappedBy: 'website', orphanRemoval: true)]
22-
private $pages;
22+
private Collection $pages;
2323

2424
public function __construct()
2525
{

0 commit comments

Comments
 (0)