Total Complexity | 58 |
Total Lines | 437 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like XApiObject 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 XApiObject, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | #[ORM\Entity(repositoryClass: XApiObjectRepository::class)] |
||
15 | class XApiObject |
||
16 | { |
||
17 | #[ORM\Id] |
||
18 | #[ORM\GeneratedValue] |
||
19 | #[ORM\Column] |
||
20 | private ?int $identifier = null; |
||
21 | |||
22 | #[ORM\Column(length: 255, nullable: true)] |
||
23 | private ?string $type = null; |
||
24 | |||
25 | #[ORM\Column(length: 255, nullable: true)] |
||
26 | private ?string $activityId = null; |
||
27 | |||
28 | #[ORM\Column(nullable: true)] |
||
29 | private ?bool $hasActivityDefinition = null; |
||
30 | |||
31 | #[ORM\Column(nullable: true)] |
||
32 | private ?bool $hasActivityName = null; |
||
33 | |||
34 | #[ORM\Column(nullable: true)] |
||
35 | private ?array $activityName = null; |
||
36 | |||
37 | #[ORM\Column(nullable: true)] |
||
38 | private ?bool $hasActivityDescription = null; |
||
39 | |||
40 | #[ORM\Column(nullable: true)] |
||
41 | private ?array $activityDescription = null; |
||
42 | |||
43 | #[ORM\Column(length: 255, nullable: true)] |
||
44 | private ?string $activityType = null; |
||
45 | |||
46 | #[ORM\Column(length: 255, nullable: true)] |
||
47 | private ?string $activityMoreInfo = null; |
||
48 | |||
49 | #[ORM\Column(length: 255, nullable: true)] |
||
50 | private ?string $mbox = null; |
||
51 | |||
52 | #[ORM\Column(length: 255, nullable: true)] |
||
53 | private ?string $mboxSha1Sum = null; |
||
54 | |||
55 | #[ORM\Column(length: 255, nullable: true)] |
||
56 | private ?string $openId = null; |
||
57 | |||
58 | #[ORM\Column(length: 255, nullable: true)] |
||
59 | private ?string $accountName = null; |
||
60 | |||
61 | #[ORM\Column(length: 255, nullable: true)] |
||
62 | private ?string $accountHomePage = null; |
||
63 | |||
64 | #[ORM\Column(length: 255, nullable: true)] |
||
65 | private ?string $name = null; |
||
66 | |||
67 | #[ORM\Column(length: 255, nullable: true)] |
||
68 | private ?string $referencedStatementId = null; |
||
69 | |||
70 | #[ORM\OneToOne(targetEntity: self::class, cascade: ['persist', 'remove'])] |
||
71 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
72 | private ?self $actor = null; |
||
73 | |||
74 | #[ORM\OneToOne(cascade: ['persist', 'remove'])] |
||
75 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
76 | private ?XApiVerb $verb = null; |
||
77 | |||
78 | #[ORM\OneToOne(targetEntity: self::class, cascade: ['persist', 'remove'])] |
||
79 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
80 | private ?self $object = null; |
||
81 | |||
82 | #[ORM\OneToOne(cascade: ['persist', 'remove'])] |
||
83 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
84 | private ?XApiExtensions $activityExtensions = null; |
||
85 | |||
86 | #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'members')] |
||
87 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
88 | private ?self $group = null; |
||
89 | |||
90 | /** |
||
91 | * @var Collection<int, self> |
||
92 | */ |
||
93 | #[ORM\OneToMany(mappedBy: 'group', targetEntity: self::class)] |
||
94 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
95 | private Collection $members; |
||
96 | |||
97 | #[ORM\ManyToOne(inversedBy: 'parentActivities')] |
||
98 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
99 | private ?XApiContext $parentContext = null; |
||
100 | |||
101 | #[ORM\ManyToOne(inversedBy: 'groupingActivities')] |
||
102 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
103 | private ?XApiContext $groupingContext = null; |
||
104 | |||
105 | #[ORM\ManyToOne(inversedBy: 'categoryActivities')] |
||
106 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
107 | private ?XApiContext $categoryContext = null; |
||
108 | |||
109 | #[ORM\ManyToOne(inversedBy: 'otherActivities')] |
||
110 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
111 | private ?XApiContext $otherContext = null; |
||
112 | |||
113 | public function __construct() |
||
114 | { |
||
115 | $this->members = new ArrayCollection(); |
||
116 | } |
||
117 | |||
118 | public function getIdentifier(): ?int |
||
119 | { |
||
120 | return $this->identifier; |
||
121 | } |
||
122 | |||
123 | public function getType(): ?string |
||
124 | { |
||
125 | return $this->type; |
||
126 | } |
||
127 | |||
128 | public function setType(?string $type): static |
||
129 | { |
||
130 | $this->type = $type; |
||
131 | |||
132 | return $this; |
||
133 | } |
||
134 | |||
135 | public function getActivityId(): ?string |
||
136 | { |
||
137 | return $this->activityId; |
||
138 | } |
||
139 | |||
140 | public function setActivityId(?string $activityId): static |
||
141 | { |
||
142 | $this->activityId = $activityId; |
||
143 | |||
144 | return $this; |
||
145 | } |
||
146 | |||
147 | public function hasActivityDefinition(): ?bool |
||
148 | { |
||
149 | return $this->hasActivityDefinition; |
||
150 | } |
||
151 | |||
152 | public function setHasActivityDefinition(?bool $hasActivityDefinition): static |
||
153 | { |
||
154 | $this->hasActivityDefinition = $hasActivityDefinition; |
||
155 | |||
156 | return $this; |
||
157 | } |
||
158 | |||
159 | public function hasActivityName(): ?bool |
||
160 | { |
||
161 | return $this->hasActivityName; |
||
162 | } |
||
163 | |||
164 | public function setHasActivityName(?bool $hasActivityName): static |
||
165 | { |
||
166 | $this->hasActivityName = $hasActivityName; |
||
167 | |||
168 | return $this; |
||
169 | } |
||
170 | |||
171 | public function getActivityName(): ?array |
||
172 | { |
||
173 | return $this->activityName; |
||
174 | } |
||
175 | |||
176 | public function setActivityName(?array $activityName): static |
||
177 | { |
||
178 | $this->activityName = $activityName; |
||
179 | |||
180 | return $this; |
||
181 | } |
||
182 | |||
183 | public function hasActivityDescription(): ?bool |
||
184 | { |
||
185 | return $this->hasActivityDescription; |
||
186 | } |
||
187 | |||
188 | public function setHasActivityDescription(?bool $hasActivityDescription): static |
||
189 | { |
||
190 | $this->hasActivityDescription = $hasActivityDescription; |
||
191 | |||
192 | return $this; |
||
193 | } |
||
194 | |||
195 | public function getActivityDescription(): ?array |
||
196 | { |
||
197 | return $this->activityDescription; |
||
198 | } |
||
199 | |||
200 | public function setActivityDescription(?array $activityDescription): static |
||
201 | { |
||
202 | $this->activityDescription = $activityDescription; |
||
203 | |||
204 | return $this; |
||
205 | } |
||
206 | |||
207 | public function getActivityType(): ?string |
||
208 | { |
||
209 | return $this->activityType; |
||
210 | } |
||
211 | |||
212 | public function setActivityType(?string $activityType): static |
||
213 | { |
||
214 | $this->activityType = $activityType; |
||
215 | |||
216 | return $this; |
||
217 | } |
||
218 | |||
219 | public function getActivityMoreInfo(): ?string |
||
220 | { |
||
221 | return $this->activityMoreInfo; |
||
222 | } |
||
223 | |||
224 | public function setActivityMoreInfo(?string $activityMoreInfo): static |
||
225 | { |
||
226 | $this->activityMoreInfo = $activityMoreInfo; |
||
227 | |||
228 | return $this; |
||
229 | } |
||
230 | |||
231 | public function getMbox(): ?string |
||
232 | { |
||
233 | return $this->mbox; |
||
234 | } |
||
235 | |||
236 | public function setMbox(?string $mbox): static |
||
237 | { |
||
238 | $this->mbox = $mbox; |
||
239 | |||
240 | return $this; |
||
241 | } |
||
242 | |||
243 | public function getMboxSha1Sum(): ?string |
||
244 | { |
||
245 | return $this->mboxSha1Sum; |
||
246 | } |
||
247 | |||
248 | public function setMboxSha1Sum(?string $mboxSha1Sum): static |
||
249 | { |
||
250 | $this->mboxSha1Sum = $mboxSha1Sum; |
||
251 | |||
252 | return $this; |
||
253 | } |
||
254 | |||
255 | public function getOpenId(): ?string |
||
256 | { |
||
257 | return $this->openId; |
||
258 | } |
||
259 | |||
260 | public function setOpenId(?string $openId): static |
||
261 | { |
||
262 | $this->openId = $openId; |
||
263 | |||
264 | return $this; |
||
265 | } |
||
266 | |||
267 | public function getAccountName(): ?string |
||
268 | { |
||
269 | return $this->accountName; |
||
270 | } |
||
271 | |||
272 | public function setAccountName(?string $accountName): static |
||
273 | { |
||
274 | $this->accountName = $accountName; |
||
275 | |||
276 | return $this; |
||
277 | } |
||
278 | |||
279 | public function getAccountHomePage(): ?string |
||
280 | { |
||
281 | return $this->accountHomePage; |
||
282 | } |
||
283 | |||
284 | public function setAccountHomePage(?string $accountHomePage): static |
||
285 | { |
||
286 | $this->accountHomePage = $accountHomePage; |
||
287 | |||
288 | return $this; |
||
289 | } |
||
290 | |||
291 | public function getName(): ?string |
||
292 | { |
||
293 | return $this->name; |
||
294 | } |
||
295 | |||
296 | public function setName(?string $name): static |
||
297 | { |
||
298 | $this->name = $name; |
||
299 | |||
300 | return $this; |
||
301 | } |
||
302 | |||
303 | public function getReferencedStatementId(): ?string |
||
304 | { |
||
305 | return $this->referencedStatementId; |
||
306 | } |
||
307 | |||
308 | public function setReferencedStatementId(?string $referencedStatementId): static |
||
309 | { |
||
310 | $this->referencedStatementId = $referencedStatementId; |
||
311 | |||
312 | return $this; |
||
313 | } |
||
314 | |||
315 | public function getActor(): ?self |
||
316 | { |
||
317 | return $this->actor; |
||
318 | } |
||
319 | |||
320 | public function setActor(?self $actor): static |
||
321 | { |
||
322 | $this->actor = $actor; |
||
323 | |||
324 | return $this; |
||
325 | } |
||
326 | |||
327 | public function getVerb(): ?XApiVerb |
||
328 | { |
||
329 | return $this->verb; |
||
330 | } |
||
331 | |||
332 | public function setVerb(?XApiVerb $verb): static |
||
333 | { |
||
334 | $this->verb = $verb; |
||
335 | |||
336 | return $this; |
||
337 | } |
||
338 | |||
339 | public function getObject(): ?self |
||
342 | } |
||
343 | |||
344 | public function setObject(?self $object): static |
||
345 | { |
||
346 | $this->object = $object; |
||
347 | |||
348 | return $this; |
||
349 | } |
||
350 | |||
351 | public function getActivityExtensions(): ?XApiExtensions |
||
352 | { |
||
353 | return $this->activityExtensions; |
||
354 | } |
||
355 | |||
356 | public function setActivityExtensions(?XApiExtensions $activityExtensions): static |
||
357 | { |
||
358 | $this->activityExtensions = $activityExtensions; |
||
359 | |||
360 | return $this; |
||
361 | } |
||
362 | |||
363 | public function getGroup(): ?self |
||
364 | { |
||
365 | return $this->group; |
||
366 | } |
||
367 | |||
368 | public function setGroup(?self $group): static |
||
369 | { |
||
370 | $this->group = $group; |
||
371 | |||
372 | return $this; |
||
373 | } |
||
374 | |||
375 | /** |
||
376 | * @return Collection<int, self> |
||
377 | */ |
||
378 | public function getMembers(): Collection |
||
379 | { |
||
380 | return $this->members; |
||
381 | } |
||
382 | |||
383 | public function addMember(self $member): static |
||
384 | { |
||
385 | if (!$this->members->contains($member)) { |
||
386 | $this->members->add($member); |
||
387 | $member->setGroup($this); |
||
388 | } |
||
389 | |||
390 | return $this; |
||
391 | } |
||
392 | |||
393 | public function removeMember(self $member): static |
||
394 | { |
||
395 | if ($this->members->removeElement($member)) { |
||
396 | // set the owning side to null (unless already changed) |
||
397 | if ($member->getGroup() === $this) { |
||
398 | $member->setGroup(null); |
||
399 | } |
||
400 | } |
||
401 | |||
402 | return $this; |
||
403 | } |
||
404 | |||
405 | public function getParentContext(): ?XApiContext |
||
406 | { |
||
407 | return $this->parentContext; |
||
408 | } |
||
409 | |||
410 | public function setParentContext(?XApiContext $parentContext): static |
||
411 | { |
||
412 | $this->parentContext = $parentContext; |
||
413 | |||
414 | return $this; |
||
415 | } |
||
416 | |||
417 | public function getGroupingContext(): ?XApiContext |
||
418 | { |
||
419 | return $this->groupingContext; |
||
420 | } |
||
421 | |||
422 | public function setGroupingContext(?XApiContext $groupingContext): static |
||
423 | { |
||
424 | $this->groupingContext = $groupingContext; |
||
425 | |||
426 | return $this; |
||
427 | } |
||
428 | |||
429 | public function getCategoryContext(): ?XApiContext |
||
430 | { |
||
431 | return $this->categoryContext; |
||
432 | } |
||
433 | |||
434 | public function setCategoryContext(?XApiContext $categoryContext): static |
||
435 | { |
||
436 | $this->categoryContext = $categoryContext; |
||
437 | |||
438 | return $this; |
||
439 | } |
||
440 | |||
441 | public function getOtherContext(): ?XApiContext |
||
444 | } |
||
445 | |||
446 | public function setOtherContext(?XApiContext $otherContext): static |
||
447 | { |
||
448 | $this->otherContext = $otherContext; |
||
449 | |||
450 | return $this; |
||
451 | } |
||
452 | } |
||
453 |