Skip to content

Commit f970630

Browse files
committed
minor #16876 [Serializer] Update serializer example using type hints (94noni)
This PR was submitted for the 6.0 branch but it was merged into the 4.4 branch instead. Discussion ---------- [Serializer] Update serializer example using type hints Hi, small proposition to upgrade code example here in the serializer doc using type hint on object to serialize to make example more robust from the input to output Before continuing on this page, I want to ask if it is useful or not Thank you! Commits ------- fd73939 Update serializer.rst
2 parents bb06b33 + fd73939 commit f970630

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

components/serializer.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ exists in your project::
7474

7575
class Person
7676
{
77-
private $age;
78-
private $name;
79-
private $sportsperson;
80-
private $createdAt;
77+
private int $age;
78+
private string $name;
79+
private bool $sportsperson;
80+
private ?\DateTime $createdAt;
8181

8282
// Getters
83-
public function getName()
83+
public function getAge(): int
8484
{
85-
return $this->name;
85+
return $this->age;
8686
}
8787

88-
public function getAge()
88+
public function getName(): string
8989
{
90-
return $this->age;
90+
return $this->name;
9191
}
9292

9393
public function getCreatedAt()
@@ -96,28 +96,28 @@ exists in your project::
9696
}
9797

9898
// Issers
99-
public function isSportsperson()
99+
public function isSportsperson(): bool
100100
{
101101
return $this->sportsperson;
102102
}
103103

104104
// Setters
105-
public function setName($name)
105+
public function setName(string $name): void
106106
{
107107
$this->name = $name;
108108
}
109109

110-
public function setAge($age)
110+
public function setAge(int $age): void
111111
{
112112
$this->age = $age;
113113
}
114114

115-
public function setSportsperson($sportsperson)
115+
public function setSportsperson(bool $sportsperson): void
116116
{
117117
$this->sportsperson = $sportsperson;
118118
}
119119

120-
public function setCreatedAt($createdAt)
120+
public function setCreatedAt(\DateTime $createdAt = null): void
121121
{
122122
$this->createdAt = $createdAt;
123123
}

0 commit comments

Comments
 (0)