Total Complexity | 49 |
Total Lines | 337 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like EventDemand 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 EventDemand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class EventDemand |
||
22 | { |
||
23 | protected string $displayMode = 'all'; |
||
24 | protected string $storagePage = ''; |
||
25 | protected ?DateTime $currentDateTime = null; |
||
26 | protected string $category = ''; |
||
27 | protected bool $includeSubcategories = false; |
||
28 | protected string $categoryConjunction = ''; |
||
29 | protected int $topEventRestriction = 0; |
||
30 | protected string $orderField = ''; |
||
31 | protected string $orderFieldAllowed = ''; |
||
32 | protected string $orderDirection = ''; |
||
33 | protected int $queryLimit = 0; |
||
34 | protected string $locationCity = ''; |
||
35 | protected string $locationCountry = ''; |
||
36 | protected int $year = 0; |
||
37 | protected int $month = 0; |
||
38 | protected int $day = 0; |
||
39 | protected ?SearchDemand $searchDemand = null; |
||
40 | protected bool $ignoreEnableFields = false; |
||
41 | protected string $timeRestrictionLow = ''; |
||
42 | protected string $timeRestrictionHigh = ''; |
||
43 | protected bool $includeCurrent = false; |
||
44 | |||
45 | /** |
||
46 | * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin |
||
47 | * |
||
48 | * @var Location|string|null |
||
49 | */ |
||
50 | protected $location; |
||
51 | |||
52 | /** |
||
53 | * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin |
||
54 | * |
||
55 | * @var Speaker|string|null |
||
56 | */ |
||
57 | protected $speaker; |
||
58 | |||
59 | /** |
||
60 | * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin |
||
61 | * |
||
62 | * @var Organisator|string|null |
||
63 | */ |
||
64 | protected $organisator; |
||
65 | |||
66 | public function getDisplayMode(): string |
||
67 | { |
||
68 | return $this->displayMode; |
||
69 | } |
||
70 | |||
71 | public function setDisplayMode(string $displayMode): void |
||
72 | { |
||
73 | $this->displayMode = $displayMode; |
||
74 | } |
||
75 | |||
76 | public function getStoragePage(): string |
||
77 | { |
||
78 | return $this->storagePage; |
||
79 | } |
||
80 | |||
81 | public function setStoragePage(string $storagePage): void |
||
82 | { |
||
83 | $this->storagePage = $storagePage; |
||
84 | } |
||
85 | |||
86 | public function setCurrentDateTime(DateTime $currentDateTime): void |
||
87 | { |
||
88 | $this->currentDateTime = $currentDateTime; |
||
89 | } |
||
90 | |||
91 | public function getCurrentDateTime(): DateTime |
||
92 | { |
||
93 | return $this->currentDateTime ?? new DateTime(); |
||
94 | } |
||
95 | |||
96 | public function setCategory(string $category): void |
||
97 | { |
||
98 | $this->category = $category; |
||
99 | } |
||
100 | |||
101 | public function getCategory(): string |
||
102 | { |
||
103 | return $this->category; |
||
104 | } |
||
105 | |||
106 | public function getIncludeSubcategories(): bool |
||
107 | { |
||
108 | return $this->includeSubcategories; |
||
109 | } |
||
110 | |||
111 | public function setIncludeSubcategories(bool $includeSubcategories): void |
||
114 | } |
||
115 | |||
116 | public function getTopEventRestriction(): int |
||
117 | { |
||
118 | return $this->topEventRestriction; |
||
119 | } |
||
120 | |||
121 | public function setTopEventRestriction(int $topEventRestriction): void |
||
122 | { |
||
123 | $this->topEventRestriction = $topEventRestriction; |
||
124 | } |
||
125 | |||
126 | public function getOrderDirection(): string |
||
127 | { |
||
128 | return $this->orderDirection; |
||
129 | } |
||
130 | |||
131 | public function setOrderDirection(string $orderDirection): void |
||
132 | { |
||
133 | $this->orderDirection = $orderDirection; |
||
134 | } |
||
135 | |||
136 | public function getOrderField(): string |
||
137 | { |
||
138 | return $this->orderField; |
||
139 | } |
||
140 | |||
141 | public function setOrderField(string $orderField): void |
||
142 | { |
||
143 | $this->orderField = $orderField; |
||
144 | } |
||
145 | |||
146 | public function getOrderFieldAllowed(): string |
||
147 | { |
||
148 | return $this->orderFieldAllowed; |
||
149 | } |
||
150 | |||
151 | public function setOrderFieldAllowed(string $orderFieldAllowed): void |
||
152 | { |
||
153 | $this->orderFieldAllowed = $orderFieldAllowed; |
||
154 | } |
||
155 | |||
156 | public function getQueryLimit(): int |
||
157 | { |
||
158 | return $this->queryLimit; |
||
159 | } |
||
160 | |||
161 | public function setQueryLimit(int $queryLimit): void |
||
162 | { |
||
163 | $this->queryLimit = $queryLimit; |
||
164 | } |
||
165 | |||
166 | public function getLocationCity(): string |
||
167 | { |
||
168 | return $this->locationCity; |
||
169 | } |
||
170 | |||
171 | public function setLocationCity(string $locationCity): void |
||
172 | { |
||
173 | $this->locationCity = $locationCity; |
||
174 | } |
||
175 | |||
176 | public function getLocationCountry(): string |
||
177 | { |
||
178 | return $this->locationCountry; |
||
179 | } |
||
180 | |||
181 | public function setLocationCountry(string $locationCountry): void |
||
182 | { |
||
183 | $this->locationCountry = $locationCountry; |
||
184 | } |
||
185 | |||
186 | public function getYear(): int |
||
187 | { |
||
188 | return $this->year; |
||
189 | } |
||
190 | |||
191 | public function setYear(int $year): void |
||
192 | { |
||
193 | $this->year = $year; |
||
194 | } |
||
195 | |||
196 | public function getMonth(): int |
||
197 | { |
||
198 | return $this->month; |
||
199 | } |
||
200 | |||
201 | public function setMonth(int $month): void |
||
202 | { |
||
203 | $this->month = $month; |
||
204 | } |
||
205 | |||
206 | public function getDay(): int |
||
207 | { |
||
208 | return $this->day; |
||
209 | } |
||
210 | |||
211 | public function setDay(int $day): void |
||
212 | { |
||
213 | $this->day = $day; |
||
214 | } |
||
215 | |||
216 | public function getSearchDemand(): ?SearchDemand |
||
217 | { |
||
218 | return $this->searchDemand; |
||
219 | } |
||
220 | |||
221 | public function setSearchDemand(?SearchDemand $searchDemand): void |
||
222 | { |
||
223 | $this->searchDemand = $searchDemand; |
||
224 | } |
||
225 | |||
226 | public function getCategoryConjunction(): string |
||
227 | { |
||
228 | return $this->categoryConjunction; |
||
229 | } |
||
230 | |||
231 | public function setCategoryConjunction(string $categoryConjunction): void |
||
232 | { |
||
233 | $this->categoryConjunction = $categoryConjunction; |
||
234 | } |
||
235 | |||
236 | public function getIgnoreEnableFields(): bool |
||
239 | } |
||
240 | |||
241 | public function setIgnoreEnableFields(bool $ignoreEnableFields): void |
||
242 | { |
||
243 | $this->ignoreEnableFields = $ignoreEnableFields; |
||
244 | } |
||
245 | |||
246 | public function getTimeRestrictionLow(): string |
||
247 | { |
||
248 | return $this->timeRestrictionLow; |
||
249 | } |
||
250 | |||
251 | public function setTimeRestrictionLow(string $timeRestrictionLow): void |
||
252 | { |
||
253 | $this->timeRestrictionLow = $timeRestrictionLow; |
||
254 | } |
||
255 | |||
256 | public function getTimeRestrictionHigh(): string |
||
257 | { |
||
258 | return $this->timeRestrictionHigh; |
||
259 | } |
||
260 | |||
261 | public function setTimeRestrictionHigh(string $timeRestrictionHigh): void |
||
262 | { |
||
263 | $this->timeRestrictionHigh = $timeRestrictionHigh; |
||
264 | } |
||
265 | |||
266 | public function getIncludeCurrent(): bool |
||
267 | { |
||
268 | return $this->includeCurrent; |
||
269 | } |
||
270 | |||
271 | public function setIncludeCurrent(bool $includeCurrent): void |
||
272 | { |
||
273 | $this->includeCurrent = $includeCurrent; |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * @return Location|string|null |
||
278 | */ |
||
279 | public function getLocation() |
||
280 | { |
||
281 | return $this->location; |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * @param Location|string|null $location |
||
286 | */ |
||
287 | public function setLocation($location): void |
||
288 | { |
||
289 | $this->location = $location; |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return Speaker|string|null |
||
294 | */ |
||
295 | public function getSpeaker() |
||
296 | { |
||
297 | return $this->speaker; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * @param Speaker|string|null $speaker |
||
302 | */ |
||
303 | public function setSpeaker($speaker): void |
||
304 | { |
||
305 | $this->speaker = $speaker; |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @return Organisator|string|null |
||
310 | */ |
||
311 | public function getOrganisator() |
||
312 | { |
||
313 | return $this->organisator; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @param Organisator|string|null $organisator |
||
318 | */ |
||
319 | public function setOrganisator($organisator): void |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * Creates a new EventDemand object from the given settings. Respects recursive setting for storage page |
||
326 | * and extends all PIDs to children if set. |
||
327 | * |
||
328 | * @param array $settings |
||
329 | * @return EventDemand |
||
330 | */ |
||
331 | public static function createFromSettings(array $settings = []): self |
||
358 | } |
||
359 | } |
||
360 |