Total Complexity | 70 |
Total Lines | 560 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like ExtensionStruct 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 ExtensionStruct, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
12 | class ExtensionStruct extends Struct |
||
13 | { |
||
14 | public const EXTENSION_TYPE_APP = 'app'; |
||
15 | public const EXTENSION_TYPE_PLUGIN = 'plugin'; |
||
16 | public const SOURCE_LOCAL = 'local'; |
||
17 | public const SOURCE_STORE = 'store'; |
||
18 | |||
19 | /** |
||
20 | * @var int|null is null for private extensions |
||
21 | */ |
||
22 | protected $id; |
||
23 | |||
24 | /** |
||
25 | * @var string|null is null for not installed extensions |
||
26 | */ |
||
27 | protected $localId; |
||
28 | |||
29 | /** |
||
30 | * @see AppEntity::$name |
||
31 | * @see PluginEntity::$name |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $name; |
||
36 | |||
37 | /** |
||
38 | * @see AppEntity::$label |
||
39 | * @see PluginEntity::$label |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $label; |
||
44 | |||
45 | /** |
||
46 | * @see AppEntity::$description |
||
47 | * @see PluginEntity::$description |
||
48 | * |
||
49 | * @var string|null |
||
50 | */ |
||
51 | protected $description; |
||
52 | |||
53 | /** |
||
54 | * @var string|null is null for private extensions |
||
55 | */ |
||
56 | protected $shortDescription; |
||
57 | |||
58 | /** |
||
59 | * @see AppEntity::$author |
||
60 | * @see PluginEntity::$author |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $producerName; |
||
65 | |||
66 | /** |
||
67 | * @see AppEntity::$license |
||
68 | * @see PluginEntity::$license |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $license; |
||
73 | |||
74 | /** |
||
75 | * @see AppEntity::$version |
||
76 | * @see PluginEntity::$version |
||
77 | * |
||
78 | * @var string|null for store details |
||
79 | */ |
||
80 | protected $version; |
||
81 | |||
82 | /** |
||
83 | * @var string|null |
||
84 | */ |
||
85 | protected $latestVersion; |
||
86 | |||
87 | /** |
||
88 | * privacyPolicyLink from store |
||
89 | * |
||
90 | * @see AppEntity::$privacy |
||
91 | * |
||
92 | * @var string|null null for plugins |
||
93 | */ |
||
94 | protected $privacyPolicyLink; |
||
95 | |||
96 | /** |
||
97 | * languages property from store |
||
98 | * |
||
99 | * @var array<string> |
||
100 | */ |
||
101 | protected $languages = []; |
||
102 | |||
103 | /** |
||
104 | * @var float|null null for private extensions |
||
105 | */ |
||
106 | protected $rating; |
||
107 | |||
108 | /** |
||
109 | * @var int total of given ratings |
||
110 | */ |
||
111 | protected $numberOfRatings = 0; |
||
112 | |||
113 | /** |
||
114 | * @var VariantCollection|null |
||
115 | */ |
||
116 | protected $variants; |
||
117 | |||
118 | /** |
||
119 | * @var FaqCollection|null |
||
120 | */ |
||
121 | protected $faq; |
||
122 | |||
123 | /** |
||
124 | * @var BinaryCollection|null |
||
125 | */ |
||
126 | protected $binaries; |
||
127 | |||
128 | /** |
||
129 | * @var ImageCollection |
||
130 | */ |
||
131 | protected $images; |
||
132 | |||
133 | /** |
||
134 | * @var string|null |
||
135 | */ |
||
136 | protected $icon; |
||
137 | |||
138 | /** |
||
139 | * @var string|null |
||
140 | */ |
||
141 | protected $iconRaw; |
||
142 | |||
143 | /** |
||
144 | * @var StoreCategoryCollection|null |
||
145 | */ |
||
146 | protected $categories; |
||
147 | |||
148 | /** |
||
149 | * @var PermissionCollection|null |
||
150 | */ |
||
151 | protected $permissions; |
||
152 | |||
153 | /** |
||
154 | * @var bool |
||
155 | */ |
||
156 | protected $active = false; |
||
157 | |||
158 | /** |
||
159 | * @var string 'app' | 'plugin' |
||
160 | */ |
||
161 | protected $type; |
||
162 | |||
163 | /** |
||
164 | * @var bool |
||
165 | */ |
||
166 | protected $isTheme; |
||
167 | |||
168 | /** |
||
169 | * @see AppEntity::$configurable |
||
170 | * |
||
171 | * @var bool |
||
172 | */ |
||
173 | protected $configurable; |
||
174 | |||
175 | /** |
||
176 | * @see AppEntity::$privacyPolicyExtensions |
||
177 | * |
||
178 | * @var string|null |
||
179 | */ |
||
180 | protected $privacyPolicyExtensions; |
||
181 | |||
182 | /** |
||
183 | * @var LicenseStruct|null |
||
184 | */ |
||
185 | protected $storeLicense; |
||
186 | |||
187 | /** |
||
188 | * @var ExtensionStruct|null |
||
189 | */ |
||
190 | protected $storeExtension; |
||
191 | |||
192 | /** |
||
193 | * @var \DateTimeInterface|null |
||
194 | */ |
||
195 | protected $installedAt; |
||
196 | |||
197 | /** |
||
198 | * @var array |
||
199 | */ |
||
200 | protected $notices = []; |
||
201 | |||
202 | /** |
||
203 | * Is this extension locally available or only in store |
||
204 | * |
||
205 | * @var string |
||
206 | */ |
||
207 | protected $source = self::SOURCE_LOCAL; |
||
208 | |||
209 | /** |
||
210 | * Is the update local or in store |
||
211 | * |
||
212 | * @var string |
||
213 | */ |
||
214 | protected $updateSource = self::SOURCE_LOCAL; |
||
215 | |||
216 | public static function fromArray(array $data): ExtensionStruct |
||
217 | { |
||
218 | return (new self())->assign($data); |
||
219 | } |
||
220 | |||
221 | public function getId(): ?int |
||
222 | { |
||
223 | return $this->id; |
||
224 | } |
||
225 | |||
226 | public function setId(?int $id): void |
||
227 | { |
||
228 | $this->id = $id; |
||
229 | } |
||
230 | |||
231 | public function getLocalId(): ?string |
||
232 | { |
||
233 | return $this->localId; |
||
234 | } |
||
235 | |||
236 | public function setLocalId(?string $localId): void |
||
237 | { |
||
238 | $this->localId = $localId; |
||
239 | } |
||
240 | |||
241 | public function getName(): string |
||
242 | { |
||
243 | return $this->name; |
||
244 | } |
||
245 | |||
246 | public function setName(string $name): void |
||
247 | { |
||
248 | $this->name = $name; |
||
249 | } |
||
250 | |||
251 | public function getLabel(): string |
||
252 | { |
||
253 | return $this->label; |
||
254 | } |
||
255 | |||
256 | public function setLabel(string $label): void |
||
257 | { |
||
258 | $this->label = $label; |
||
259 | } |
||
260 | |||
261 | public function getDescription(): ?string |
||
262 | { |
||
263 | return $this->description; |
||
264 | } |
||
265 | |||
266 | public function setDescription(?string $description): void |
||
267 | { |
||
268 | $this->description = $description; |
||
269 | } |
||
270 | |||
271 | public function getShortDescription(): ?string |
||
272 | { |
||
273 | return $this->shortDescription; |
||
274 | } |
||
275 | |||
276 | public function setShortDescription(?string $shortDescription): void |
||
277 | { |
||
278 | $this->shortDescription = $shortDescription; |
||
279 | } |
||
280 | |||
281 | public function getProducerName(): string |
||
282 | { |
||
283 | return $this->producerName; |
||
284 | } |
||
285 | |||
286 | public function setProducerName(string $producerName): void |
||
287 | { |
||
288 | $this->producerName = $producerName; |
||
289 | } |
||
290 | |||
291 | public function getLicense(): ?string |
||
292 | { |
||
293 | return $this->license; |
||
294 | } |
||
295 | |||
296 | public function setLicense(string $license): void |
||
297 | { |
||
298 | $this->license = $license; |
||
299 | } |
||
300 | |||
301 | public function getVersion(): ?string |
||
302 | { |
||
303 | return $this->version; |
||
304 | } |
||
305 | |||
306 | public function setVersion(string $version): void |
||
309 | } |
||
310 | |||
311 | public function getLatestVersion(): ?string |
||
312 | { |
||
313 | return $this->latestVersion; |
||
314 | } |
||
315 | |||
316 | public function setLatestVersion(?string $latestVersion): void |
||
317 | { |
||
318 | $this->latestVersion = $latestVersion; |
||
319 | } |
||
320 | |||
321 | public function getPrivacyPolicyLink(): ?string |
||
322 | { |
||
323 | return $this->privacyPolicyLink; |
||
324 | } |
||
325 | |||
326 | public function setPrivacyPolicyLink(?string $privacyPolicyLink): void |
||
327 | { |
||
328 | $this->privacyPolicyLink = $privacyPolicyLink; |
||
329 | } |
||
330 | |||
331 | public function getVariants(): ?VariantCollection |
||
332 | { |
||
333 | return $this->variants; |
||
334 | } |
||
335 | |||
336 | public function setVariants(VariantCollection $variants): void |
||
337 | { |
||
338 | $this->variants = $variants; |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * @return array<string> |
||
343 | */ |
||
344 | public function getLanguages(): ?array |
||
345 | { |
||
346 | return $this->languages; |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @param array<string> $languages |
||
351 | */ |
||
352 | public function setLanguages(array $languages): void |
||
353 | { |
||
354 | $this->languages = $languages; |
||
355 | } |
||
356 | |||
357 | public function getRating(): ?float |
||
358 | { |
||
359 | return $this->rating; |
||
360 | } |
||
361 | |||
362 | public function setRating(float $rating): void |
||
363 | { |
||
364 | $this->rating = $rating; |
||
365 | } |
||
366 | |||
367 | public function getNumberOfRatings(): int |
||
368 | { |
||
369 | return $this->numberOfRatings; |
||
370 | } |
||
371 | |||
372 | public function setNumberOfRatings(int $numberOfRatings): void |
||
373 | { |
||
374 | $this->numberOfRatings = $numberOfRatings; |
||
375 | } |
||
376 | |||
377 | public function getFaq(): ?FaqCollection |
||
378 | { |
||
379 | return $this->faq; |
||
380 | } |
||
381 | |||
382 | public function setFaq(FaqCollection $faq): void |
||
383 | { |
||
384 | $this->faq = $faq; |
||
385 | } |
||
386 | |||
387 | public function getBinaries(): ?BinaryCollection |
||
388 | { |
||
389 | return $this->binaries; |
||
390 | } |
||
391 | |||
392 | public function setBinaries(BinaryCollection $binaries): void |
||
393 | { |
||
394 | $this->binaries = $binaries; |
||
395 | } |
||
396 | |||
397 | public function getImages(): ImageCollection |
||
398 | { |
||
399 | return $this->images; |
||
400 | } |
||
401 | |||
402 | public function setImages(ImageCollection $images): void |
||
403 | { |
||
404 | $this->images = $images; |
||
405 | } |
||
406 | |||
407 | public function getCategories(): ?StoreCategoryCollection |
||
408 | { |
||
409 | return $this->categories; |
||
410 | } |
||
411 | |||
412 | public function setCategories(StoreCategoryCollection $categories): void |
||
413 | { |
||
414 | $this->categories = $categories; |
||
415 | } |
||
416 | |||
417 | public function getIcon(): ?string |
||
418 | { |
||
419 | return $this->icon; |
||
420 | } |
||
421 | |||
422 | public function setIcon(?string $icon): void |
||
423 | { |
||
424 | $this->icon = $icon; |
||
425 | } |
||
426 | |||
427 | public function getIconRaw(): ?string |
||
428 | { |
||
429 | return $this->iconRaw; |
||
430 | } |
||
431 | |||
432 | public function setIconRaw(string $iconRaw): void |
||
433 | { |
||
434 | $this->iconRaw = $iconRaw; |
||
435 | } |
||
436 | |||
437 | public function getPermissions(): ?PermissionCollection |
||
438 | { |
||
439 | return $this->permissions; |
||
440 | } |
||
441 | |||
442 | public function setPermissions(?PermissionCollection $permissions): void |
||
443 | { |
||
444 | $this->permissions = $permissions; |
||
445 | } |
||
446 | |||
447 | public function getCategorizedPermissions(): array |
||
448 | { |
||
449 | if ($this->permissions === null) { |
||
450 | return []; |
||
451 | } |
||
452 | |||
453 | return $this->permissions->getCategorizedPermissions(); |
||
454 | } |
||
455 | |||
456 | public function jsonSerialize(): array |
||
457 | { |
||
458 | $vars = get_object_vars($this); |
||
459 | $vars['permissions'] = $this->getCategorizedPermissions(); |
||
460 | |||
461 | return $vars; |
||
462 | } |
||
463 | |||
464 | public function getActive(): bool |
||
465 | { |
||
466 | return $this->active; |
||
467 | } |
||
468 | |||
469 | public function setActive(bool $active): void |
||
470 | { |
||
471 | $this->active = $active; |
||
472 | } |
||
473 | |||
474 | public function getType(): string |
||
475 | { |
||
476 | return $this->type; |
||
477 | } |
||
478 | |||
479 | public function setType(string $type): void |
||
480 | { |
||
481 | $this->type = $type; |
||
482 | } |
||
483 | |||
484 | public function isTheme(): bool |
||
485 | { |
||
486 | return $this->isTheme; |
||
487 | } |
||
488 | |||
489 | public function setIsTheme(bool $isTheme): void |
||
490 | { |
||
491 | $this->isTheme = $isTheme; |
||
492 | } |
||
493 | |||
494 | public function isConfigurable(): bool |
||
495 | { |
||
496 | return $this->configurable; |
||
497 | } |
||
498 | |||
499 | public function setConfigurable(bool $configurable): void |
||
500 | { |
||
501 | $this->configurable = $configurable; |
||
502 | } |
||
503 | |||
504 | public function getPrivacyPolicyExtensions(): ?string |
||
505 | { |
||
506 | return $this->privacyPolicyExtensions; |
||
507 | } |
||
508 | |||
509 | public function setPrivacyPolicyExtensions(?string $privacyPolicyExtensions): void |
||
510 | { |
||
511 | $this->privacyPolicyExtensions = $privacyPolicyExtensions; |
||
512 | } |
||
513 | |||
514 | public function getStoreLicense(): ?LicenseStruct |
||
515 | { |
||
516 | return $this->storeLicense; |
||
517 | } |
||
518 | |||
519 | public function setStoreLicense(?LicenseStruct $storeLicense): void |
||
520 | { |
||
521 | $this->storeLicense = $storeLicense; |
||
522 | } |
||
523 | |||
524 | public function getInstalledAt(): ?\DateTimeInterface |
||
525 | { |
||
526 | return $this->installedAt; |
||
527 | } |
||
528 | |||
529 | public function setInstalledAt(?\DateTimeInterface $installedAt): void |
||
530 | { |
||
531 | $this->installedAt = $installedAt; |
||
532 | } |
||
533 | |||
534 | public function getNotices(): array |
||
535 | { |
||
536 | return $this->notices; |
||
537 | } |
||
538 | |||
539 | public function setNotices(array $notices): void |
||
542 | } |
||
543 | |||
544 | public function getSource(): string |
||
545 | { |
||
546 | return $this->source; |
||
547 | } |
||
548 | |||
549 | public function setSource(string $source): void |
||
550 | { |
||
551 | $this->source = $source; |
||
552 | } |
||
553 | |||
554 | public function getUpdateSource(): string |
||
557 | } |
||
558 | |||
559 | public function setUpdateSource(string $updateSource): void |
||
560 | { |
||
561 | $this->updateSource = $updateSource; |
||
562 | } |
||
563 | |||
564 | public function getStoreExtension(): ?ExtensionStruct |
||
565 | { |
||
566 | return $this->storeExtension; |
||
567 | } |
||
568 | |||
569 | public function setStoreExtension(?ExtensionStruct $storeExtension): void |
||
570 | { |
||
571 | $this->storeExtension = $storeExtension; |
||
572 | } |
||
573 | } |
||
574 |