Passed
Pull Request — master (#8)
by Derek Stephen
10:36
created

Person::setBirthplace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Del\Person\Entity;
6
7
use DateTimeInterface;
8
use Del\Entity\Country;
9
use Del\Factory\CountryFactory;
10
use Doctrine\ORM\Mapping as ORM;
11
use JsonSerializable;
12
13
#[ORM\Entity(repositoryClass: '\Del\Person\Repository\PersonRepository')]
14
class Person implements JsonSerializable
15
{
16
    #[ORM\Id]
17
    #[ORM\Column(type: 'integer')]
18
    #[ORM\GeneratedValue]
19
    private ?int $id = null;
20
21
    #[ORM\Column(type: 'string', length: 60, nullable: true)]
22
    private ?string $firstname = '';
23
24
    #[ORM\Column(type: 'string', length: 60, nullable: true)]
25
    private ?string $middlename = '';
26
27
    #[ORM\Column(type: 'string', length: 60, nullable: true)]
28
    private ?string $lastname = '';
29
30
    #[ORM\Column(type: 'string', length: 50, nullable: true)]
31
    private ?string $aka = '';
32
33
    #[ORM\Column(type: 'date', nullable: true)]
34
    private ?DateTimeInterface $dob = null;
35
36
    #[ORM\Column(type: 'string', length: 50, nullable: true)]
37
    private ?string $birthplace = '';
38
39
    #[ORM\Column(type: 'string', length: 3, nullable: true)]
40
    private ?string $country = '';
41
42
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
43
    private ?string $image = '';
44
45
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
46
    private ?string $backgroundImage = '';
47
48
    public function getId(): ?int
49
    {
50
        return $this->id;
51
    }
52
53
    public function setId(int $id): void
54
    {
55
        $this->id = $id;
56 9
    }
57
58 9
    public function getCountry(): ?Country
59
    {
60
        return $this->country ? CountryFactory::generate($this->country) : null;
61
    }
62
63
    public function setCountry(Country $country): void
64
    {
65 9
        $this->country = $country->getIso();
66
    }
67 9
68 9
    public function getFirstname(): ?string
69
    {
70
        return $this->firstname;
71
    }
72
73
    public function setFirstname(string $firstname): void
74
    {
75 3
        $this->firstname = $firstname;
76
    }
77 3
78
    public function getMiddlename(): ?string
79
    {
80
        return $this->middlename;
81
    }
82
83
    public function setMiddlename(string $middlename): void
84 5
    {
85
        $this->middlename = $middlename;
86 5
    }
87 5
88
    public function getLastname(): ?string
89
    {
90
        return $this->lastname;
91
    }
92
93 5
    public function setLastname(string $lastname): void
94
    {
95 5
        $this->lastname = $lastname;
96
    }
97
98
    public function getAka(): ?string
99
    {
100
        return $this->aka;
101
    }
102 7
103
    public function setAka(string $aka): void
104 7
    {
105 7
        $this->aka = $aka;
106
    }
107
108
    public function getDob(): ?DateTime
0 ignored issues
show
Bug introduced by
The type Del\Person\Entity\DateTime was not found. Did you mean DateTime? If so, make sure to prefix the type with \.
Loading history...
109
    {
110
        return $this->dob;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->dob could return the type DateTimeInterface which is incompatible with the type-hinted return Del\Person\Entity\DateTime|null. Consider adding an additional type-check to rule them out.
Loading history...
111 4
    }
112
113 4
    public function setDob(DateTime $dob): void
114
    {
115
        $this->dob = $dob;
116
    }
117
118
    public function getBirthplace(): ?string
119
    {
120 6
        return $this->birthplace;
121
    }
122 6
123 6
    public function setBirthplace(string $birthplace): void
124
    {
125
        $this->birthplace = $birthplace;
126
    }
127
128
    public function getImage(): ?string
129 4
    {
130
        return $this->image;
131 4
    }
132
133
    public function setImage(string $image): void
134
    {
135
        $this->image = $image;
136
    }
137
138 6
    public function getBackgroundImage(): ?string
139
    {
140 6
        return $this->backgroundImage;
141 6
    }
142
143
    public function setBackgroundImage(string $backgroundImage): void
144
    {
145
        $this->backgroundImage = $backgroundImage;
146
    }
147 5
148
    public function getFullName($includeMiddleNames = false): string
149 5
    {
150
        $middleName = $includeMiddleNames && $this->middlename ? ' ' . $this->middlename : '';
151
152
        return $this->firstname . $middleName . ' ' . $this->lastname;
153
    }
154
155
    public function toArray(): array
156 5
    {
157
        return [
158 5
            'id' => $this->getId(),
159 5
            'firstname' => $this->getFirstname(),
160
            'middlename' => $this->getMiddlename(),
161
            'lastname' => $this->getLastname(),
162
            'aka' => $this->getAka(),
163
            'dob' => $this->getDob(),
164
            'birthplace' => $this->getBirthplace(),
165 4
            'country' => $this->country ? $this->getCountry()->getIso() : null,
166
            'image' => $this->getImage(),
167 4
            'backgrundImage' => $this->getImage(),
168
        ];
169
    }
170
171
    public function jsonSerialize(): array
172
    {
173
        return $this->toArray();
174 5
    }
175
}
176