Skip to content

Commit b6b564b

Browse files
committed
Implements JsonSerializable
1 parent e3911db commit b6b564b

File tree

8 files changed

+58
-3
lines changed

8 files changed

+58
-3
lines changed

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Geography/Address/AddressElement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace Talentify\ValueObject\Geography\Address;
66

7+
use JsonSerializable;
78
use Talentify\ValueObject\ValueObject;
89

9-
interface AddressElement extends ValueObject
10+
interface AddressElement extends ValueObject, JsonSerializable
1011
{
1112
public function getFormatted() : string;
1213
}

src/Geography/Address/City.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getName() : string
3737

3838
public function equals(?ValueObject $object) : bool
3939
{
40-
if (! $object instanceof self) {
40+
if (!$object instanceof self) {
4141
return false;
4242
}
4343

@@ -53,4 +53,11 @@ public function __toString() : string
5353
{
5454
return $this->name;
5555
}
56+
57+
public function jsonSerialize()
58+
{
59+
return [
60+
'name' => $this->name,
61+
];
62+
}
5663
}

src/Geography/Address/Country.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use InvalidArgumentException;
88
use Talentify\ValueObject\StringUtils;
99
use Talentify\ValueObject\ValueObject;
10+
1011
use function strlen;
1112

1213
class Country implements AddressElement
@@ -136,6 +137,16 @@ public function __toString() : string
136137
if ($this->isoAlpha3 !== null) {
137138
return strtoupper($this->isoAlpha3);
138139
}
140+
139141
return $this->name;
140142
}
143+
144+
public function jsonSerialize()
145+
{
146+
return [
147+
'name' => $this->name,
148+
'isoAlpha2' => $this->isoAlpha2,
149+
'isoAlpha3' => $this->isoAlpha3,
150+
];
151+
}
141152
}

src/Geography/Address/District.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,11 @@ public function __toString() : string
5353
{
5454
return $this->name;
5555
}
56+
57+
public function jsonSerialize()
58+
{
59+
return [
60+
'name' => $this->name,
61+
];
62+
}
5663
}

src/Geography/Address/PostalCode.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getValue() : string
4141

4242
public function equals(?ValueObject $object) : bool
4343
{
44-
if (! $object instanceof self) {
44+
if (!$object instanceof self) {
4545
return false;
4646
}
4747

@@ -57,4 +57,11 @@ public function __toString() : string
5757
{
5858
return $this->value;
5959
}
60+
61+
public function jsonSerialize()
62+
{
63+
return [
64+
'value' => $this->value,
65+
];
66+
}
6067
}

src/Geography/Address/Region.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,12 @@ public function __toString() : string
100100

101101
return $this->name;
102102
}
103+
104+
public function jsonSerialize()
105+
{
106+
return [
107+
'name' => $this->name,
108+
'isoAlpha2' => $this->isoAlpha2,
109+
];
110+
}
103111
}

src/Geography/Address/Street.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,13 @@ public function __toString() : string
108108
{
109109
return $this->name;
110110
}
111+
112+
public function jsonSerialize()
113+
{
114+
return [
115+
'name' => $this->name,
116+
'number' => $this->number,
117+
'otherIdentifier' => $this->otherIdentifiers,
118+
];
119+
}
111120
}

0 commit comments

Comments
 (0)