Total Complexity | 92 |
Total Lines | 273 |
Duplicated Lines | 0 % |
Changes | 7 | ||
Bugs | 1 | Features | 0 |
Complex classes like Poi often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Poi, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Poi |
||
20 | { |
||
21 | private ?string $id = null; |
||
22 | private ?string $type = null; |
||
23 | private ?string $office = null; |
||
24 | private ?string $street = null; |
||
25 | private ?string $nr = null; |
||
26 | private ?string $zip = null; |
||
27 | private ?string $city = null; |
||
28 | private ?int $x = null; |
||
29 | private ?int $y = null; |
||
30 | private ?float $latitude = null; |
||
31 | private ?float $longitude = null; |
||
32 | |||
33 | /** @var Service[] */ |
||
34 | private array $services = []; |
||
35 | |||
36 | /** @var array<int, Day> Indexed by Day::DAY_INDEX_* */ |
||
37 | private array $hours = []; |
||
38 | |||
39 | private ?string $closedFrom = null; |
||
40 | private ?string $closedTo = null; |
||
41 | private ?string $note = null; |
||
42 | private ?string $page = null; |
||
43 | |||
44 | public function getId(): ?string |
||
45 | { |
||
46 | return $this->id; |
||
47 | } |
||
48 | |||
49 | public function setId(?string $id): void |
||
50 | { |
||
51 | $this->id = $id; |
||
52 | } |
||
53 | |||
54 | public function getType(): ?string |
||
55 | { |
||
56 | return $this->type; |
||
57 | } |
||
58 | |||
59 | public function setType(?string $type): void |
||
60 | { |
||
61 | $this->type = $type; |
||
62 | } |
||
63 | |||
64 | public function getOffice(): ?string |
||
65 | { |
||
66 | return $this->office; |
||
67 | } |
||
68 | |||
69 | public function setOffice(?string $office): void |
||
70 | { |
||
71 | $this->office = $office; |
||
72 | } |
||
73 | |||
74 | public function getStreet(): ?string |
||
75 | { |
||
76 | return $this->street; |
||
77 | } |
||
78 | |||
79 | public function setStreet(?string $street): void |
||
80 | { |
||
81 | $this->street = $street; |
||
82 | } |
||
83 | |||
84 | public function getNr(): ?string |
||
85 | { |
||
86 | return $this->nr; |
||
87 | } |
||
88 | |||
89 | public function setNr(?string $nr): void |
||
90 | { |
||
91 | $this->nr = $nr; |
||
92 | } |
||
93 | |||
94 | public function getZip(): ?string |
||
95 | { |
||
96 | return $this->zip; |
||
97 | } |
||
98 | |||
99 | public function setZip(?string $zip): void |
||
100 | { |
||
101 | $this->zip = $zip; |
||
102 | } |
||
103 | |||
104 | public function getCity(): ?string |
||
105 | { |
||
106 | return $this->city; |
||
107 | } |
||
108 | |||
109 | public function setCity(?string $city): void |
||
110 | { |
||
111 | $this->city = $city; |
||
112 | } |
||
113 | |||
114 | public function getX(): ?int |
||
115 | { |
||
116 | return $this->x; |
||
117 | } |
||
118 | |||
119 | public function setX(?int $x): void |
||
120 | { |
||
121 | $this->x = $x; |
||
122 | } |
||
123 | |||
124 | public function getY(): ?int |
||
125 | { |
||
126 | return $this->y; |
||
127 | } |
||
128 | |||
129 | public function setY(?int $y): void |
||
130 | { |
||
131 | $this->y = $y; |
||
132 | } |
||
133 | |||
134 | public function getLatitude(): ?float |
||
135 | { |
||
136 | return $this->latitude; |
||
137 | } |
||
138 | |||
139 | public function setLatitude(?float $latitude): void |
||
140 | { |
||
141 | $this->latitude = $latitude; |
||
142 | } |
||
143 | |||
144 | public function getLongitude(): ?float |
||
145 | { |
||
146 | return $this->longitude; |
||
147 | } |
||
148 | |||
149 | public function setLongitude(?float $longitude): void |
||
150 | { |
||
151 | $this->longitude = $longitude; |
||
152 | } |
||
153 | |||
154 | public function getServices(): array |
||
155 | { |
||
156 | return $this->services; |
||
157 | } |
||
158 | |||
159 | public function addService(Service $service): void |
||
160 | { |
||
161 | $this->services[] = $service; |
||
162 | } |
||
163 | |||
164 | public function setServices(array $services): void |
||
165 | { |
||
166 | $this->services = $services; |
||
167 | } |
||
168 | |||
169 | public function getHours(): array |
||
170 | { |
||
171 | return $this->hours; |
||
172 | } |
||
173 | |||
174 | public function addHour(int $index, Day $day): void |
||
175 | { |
||
176 | $this->hours[$index] = $day; |
||
177 | } |
||
178 | |||
179 | public function setHours(array $hours): void |
||
180 | { |
||
181 | $this->hours = $hours; |
||
182 | } |
||
183 | |||
184 | public function getClosedFrom(): ?string |
||
185 | { |
||
186 | return $this->closedFrom; |
||
187 | } |
||
188 | |||
189 | public function setClosedFrom(?string $closedFrom): void |
||
190 | { |
||
191 | $this->closedFrom = $closedFrom; |
||
192 | } |
||
193 | |||
194 | public function getClosedTo(): ?string |
||
197 | } |
||
198 | |||
199 | public function setClosedTo(?string $closedTo): void |
||
200 | { |
||
201 | $this->closedTo = $closedTo; |
||
202 | } |
||
203 | |||
204 | public function getNote(): ?string |
||
205 | { |
||
206 | return $this->note; |
||
207 | } |
||
208 | |||
209 | public function setNote(?string $note): void |
||
210 | { |
||
211 | $this->note = $note; |
||
212 | } |
||
213 | |||
214 | public function getPage(): ?string |
||
217 | } |
||
218 | |||
219 | public function setPage(?string $page): void |
||
220 | { |
||
221 | $this->page = $page; |
||
222 | } |
||
223 | |||
224 | public static function createFromXML(SimpleXMLElement $xml): self |
||
292 | } |
||
293 | } |