Total Complexity | 50 |
Total Lines | 436 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like CGroupCategory 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 CGroupCategory, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | #[ORM\Table(name: 'c_group_category')] |
||
21 | #[ORM\Entity(repositoryClass: CGroupCategoryRepository::class)] |
||
22 | class CGroupCategory extends AbstractResource implements ResourceInterface, Stringable |
||
23 | { |
||
24 | #[ORM\Column(name: 'iid', type: 'integer')] |
||
25 | #[ORM\Id] |
||
26 | #[ORM\GeneratedValue] |
||
27 | protected ?int $iid = null; |
||
28 | |||
29 | #[Assert\NotBlank] |
||
30 | #[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
||
31 | protected string $title; |
||
32 | |||
33 | #[ORM\Column(name: 'description', type: 'text', nullable: false)] |
||
34 | protected ?string $description; |
||
35 | |||
36 | #[ORM\Column(name: 'doc_state', type: 'boolean', nullable: false)] |
||
37 | protected bool $docState; |
||
38 | |||
39 | #[ORM\Column(name: 'calendar_state', type: 'boolean', nullable: false)] |
||
40 | protected bool $calendarState; |
||
41 | |||
42 | #[ORM\Column(name: 'work_state', type: 'boolean', nullable: false)] |
||
43 | protected bool $workState; |
||
44 | |||
45 | #[ORM\Column(name: 'announcements_state', type: 'boolean', nullable: false)] |
||
46 | protected bool $announcementsState; |
||
47 | |||
48 | #[ORM\Column(name: 'forum_state', type: 'boolean', nullable: false)] |
||
49 | protected bool $forumState; |
||
50 | |||
51 | #[ORM\Column(name: 'wiki_state', type: 'boolean', nullable: false)] |
||
52 | protected bool $wikiState; |
||
53 | |||
54 | #[ORM\Column(name: 'chat_state', type: 'boolean', nullable: false)] |
||
55 | protected bool $chatState; |
||
56 | |||
57 | #[ORM\Column(name: 'max_student', type: 'integer', nullable: false)] |
||
58 | protected int $maxStudent; |
||
59 | |||
60 | #[ORM\Column(name: 'self_reg_allowed', type: 'boolean', nullable: false)] |
||
61 | protected bool $selfRegAllowed; |
||
62 | |||
63 | #[ORM\Column(name: 'self_unreg_allowed', type: 'boolean', nullable: false)] |
||
64 | protected bool $selfUnregAllowed; |
||
65 | |||
66 | #[ORM\Column(name: 'groups_per_user', type: 'integer', nullable: false)] |
||
67 | protected int $groupsPerUser; |
||
68 | |||
69 | #[ORM\Column(name: 'document_access', type: 'integer', nullable: false, options: ['default' => 0])] |
||
70 | protected int $documentAccess; |
||
71 | |||
72 | #[ORM\Column(name: 'min_student', type: 'integer', nullable: true)] |
||
73 | protected ?int $minStudent = null; |
||
74 | |||
75 | #[ORM\Column(name: 'begin_inscription_date', type: 'datetime', nullable: true)] |
||
76 | protected ?\DateTime $beginInscriptionDate = null; |
||
77 | |||
78 | #[ORM\Column(name: 'end_inscription_date', type: 'datetime', nullable: true)] |
||
79 | protected ?\DateTime $endInscriptionDate = null; |
||
80 | |||
81 | #[ORM\Column(name: 'only_me', type: 'boolean', options: ['default' => 0])] |
||
82 | protected bool $onlyMe = false; |
||
83 | |||
84 | #[ORM\ManyToOne(targetEntity: CPeerAssessment::class)] |
||
85 | #[ORM\JoinColumn(name: 'peer_assessment', referencedColumnName: 'id', nullable: true)] |
||
86 | protected ?CPeerAssessment $peerAssessment = null; |
||
87 | |||
88 | #[ORM\Column(name: 'allow_coach_change_options_groups', type: 'boolean', options: ['default' => 0])] |
||
89 | protected bool $allowCoachChangeOptionsGroups = false; |
||
90 | |||
91 | #[ORM\Column(name: 'allow_change_group_name', type: 'integer', nullable: true, options: ['default' => 1])] |
||
92 | protected ?int $allowChangeGroupName = 1; |
||
93 | |||
94 | #[ORM\Column(name: 'allow_autogroup', type: 'boolean', options: ['default' => 0])] |
||
95 | protected bool $allowAutogroup = false; |
||
96 | |||
97 | public function __construct() |
||
98 | { |
||
99 | $this->maxStudent = 0; |
||
100 | $this->description = ''; |
||
101 | $this->selfRegAllowed = false; |
||
102 | $this->selfUnregAllowed = false; |
||
103 | $this->groupsPerUser = 0; |
||
104 | $this->announcementsState = true; |
||
105 | $this->calendarState = true; |
||
106 | $this->documentAccess = 0; |
||
107 | $this->chatState = true; |
||
108 | $this->docState = true; |
||
109 | $this->forumState = true; |
||
110 | $this->wikiState = true; |
||
111 | $this->workState = true; |
||
112 | } |
||
113 | |||
114 | public function __toString(): string |
||
115 | { |
||
116 | return $this->getTitle(); |
||
117 | } |
||
118 | |||
119 | public function getIid(): ?int |
||
120 | { |
||
121 | return $this->iid; |
||
122 | } |
||
123 | |||
124 | public function setTitle(string $title): self |
||
125 | { |
||
126 | $this->title = $title; |
||
127 | |||
128 | return $this; |
||
129 | } |
||
130 | |||
131 | public function getTitle(): string |
||
132 | { |
||
133 | return $this->title; |
||
134 | } |
||
135 | |||
136 | public function setDescription(string $description): self |
||
137 | { |
||
138 | $this->description = $description; |
||
139 | |||
140 | return $this; |
||
141 | } |
||
142 | |||
143 | public function getDescription(): ?string |
||
144 | { |
||
145 | return $this->description; |
||
146 | } |
||
147 | |||
148 | public function setDocState(bool $docState): self |
||
149 | { |
||
150 | $this->docState = $docState; |
||
151 | |||
152 | return $this; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Get docState. |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function getDocState() |
||
161 | { |
||
162 | return $this->docState; |
||
163 | } |
||
164 | |||
165 | public function setCalendarState(bool $calendarState): self |
||
166 | { |
||
167 | $this->calendarState = $calendarState; |
||
168 | |||
169 | return $this; |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * Get calendarState. |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function getCalendarState() |
||
178 | { |
||
179 | return $this->calendarState; |
||
180 | } |
||
181 | |||
182 | public function setWorkState(bool $workState): self |
||
183 | { |
||
184 | $this->workState = $workState; |
||
185 | |||
186 | return $this; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Get workState. |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | public function getWorkState() |
||
195 | { |
||
196 | return $this->workState; |
||
197 | } |
||
198 | |||
199 | public function setAnnouncementsState(bool $announcementsState): self |
||
200 | { |
||
201 | $this->announcementsState = $announcementsState; |
||
202 | |||
203 | return $this; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Get announcementsState. |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | public function getAnnouncementsState() |
||
212 | { |
||
213 | return $this->announcementsState; |
||
214 | } |
||
215 | |||
216 | public function setForumState(bool $forumState): self |
||
217 | { |
||
218 | $this->forumState = $forumState; |
||
219 | |||
220 | return $this; |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * Get forumState. |
||
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | public function getForumState() |
||
229 | { |
||
230 | return $this->forumState; |
||
231 | } |
||
232 | |||
233 | public function setWikiState(bool $wikiState): self |
||
234 | { |
||
235 | $this->wikiState = $wikiState; |
||
236 | |||
237 | return $this; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Get wikiState. |
||
242 | * |
||
243 | * @return bool |
||
244 | */ |
||
245 | public function getWikiState() |
||
246 | { |
||
247 | return $this->wikiState; |
||
248 | } |
||
249 | |||
250 | public function setChatState(bool $chatState): self |
||
251 | { |
||
252 | $this->chatState = $chatState; |
||
253 | |||
254 | return $this; |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * Get chatState. |
||
259 | * |
||
260 | * @return bool |
||
261 | */ |
||
262 | public function getChatState() |
||
263 | { |
||
264 | return $this->chatState; |
||
265 | } |
||
266 | |||
267 | public function setMaxStudent(int $maxStudent): self |
||
268 | { |
||
269 | $this->maxStudent = $maxStudent; |
||
270 | |||
271 | return $this; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Get maxStudent. |
||
276 | * |
||
277 | * @return int |
||
278 | */ |
||
279 | public function getMaxStudent() |
||
280 | { |
||
281 | return $this->maxStudent; |
||
282 | } |
||
283 | |||
284 | public function setSelfRegAllowed(bool $selfRegAllowed): self |
||
285 | { |
||
286 | $this->selfRegAllowed = $selfRegAllowed; |
||
287 | |||
288 | return $this; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * Get selfRegAllowed. |
||
293 | * |
||
294 | * @return bool |
||
295 | */ |
||
296 | public function getSelfRegAllowed() |
||
297 | { |
||
298 | return $this->selfRegAllowed; |
||
299 | } |
||
300 | |||
301 | public function setSelfUnregAllowed(bool $selfUnregAllowed): self |
||
302 | { |
||
303 | $this->selfUnregAllowed = $selfUnregAllowed; |
||
304 | |||
305 | return $this; |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * Get selfUnregAllowed. |
||
310 | * |
||
311 | * @return bool |
||
312 | */ |
||
313 | public function getSelfUnregAllowed() |
||
314 | { |
||
315 | return $this->selfUnregAllowed; |
||
316 | } |
||
317 | |||
318 | public function setGroupsPerUser(int $groupsPerUser): self |
||
319 | { |
||
320 | $this->groupsPerUser = $groupsPerUser; |
||
321 | |||
322 | return $this; |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * Get groupsPerUser. |
||
327 | * |
||
328 | * @return int |
||
329 | */ |
||
330 | public function getGroupsPerUser() |
||
331 | { |
||
332 | return $this->groupsPerUser; |
||
333 | } |
||
334 | |||
335 | public function getDocumentAccess(): int |
||
336 | { |
||
337 | return $this->documentAccess; |
||
338 | } |
||
339 | |||
340 | public function setDocumentAccess(int $documentAccess): self |
||
341 | { |
||
342 | $this->documentAccess = $documentAccess; |
||
343 | |||
344 | return $this; |
||
345 | } |
||
346 | |||
347 | public function getMinStudent(): ?int |
||
348 | { |
||
349 | return $this->minStudent; |
||
350 | } |
||
351 | |||
352 | public function setMinStudent(?int $minStudent): self |
||
353 | { |
||
354 | $this->minStudent = $minStudent; |
||
355 | |||
356 | return $this; |
||
357 | } |
||
358 | |||
359 | public function getBeginInscriptionDate(): ?\DateTime |
||
360 | { |
||
361 | return $this->beginInscriptionDate; |
||
362 | } |
||
363 | |||
364 | public function setBeginInscriptionDate(?\DateTime $beginInscriptionDate): self |
||
365 | { |
||
366 | $this->beginInscriptionDate = $beginInscriptionDate; |
||
367 | |||
368 | return $this; |
||
369 | } |
||
370 | |||
371 | public function getEndInscriptionDate(): ?\DateTime |
||
372 | { |
||
373 | return $this->endInscriptionDate; |
||
374 | } |
||
375 | |||
376 | public function setEndInscriptionDate(?\DateTime $endInscriptionDate): self |
||
377 | { |
||
378 | $this->endInscriptionDate = $endInscriptionDate; |
||
379 | |||
380 | return $this; |
||
381 | } |
||
382 | |||
383 | public function getOnlyMe(): bool |
||
384 | { |
||
385 | return $this->onlyMe; |
||
386 | } |
||
387 | |||
388 | public function setOnlyMe(bool $onlyMe): self |
||
389 | { |
||
390 | $this->onlyMe = $onlyMe; |
||
391 | |||
392 | return $this; |
||
393 | } |
||
394 | |||
395 | public function getPeerAssessment(): ?CPeerAssessment |
||
396 | { |
||
397 | return $this->peerAssessment; |
||
398 | } |
||
399 | |||
400 | public function setPeerAssessment(?CPeerAssessment $peerAssessment): self |
||
401 | { |
||
402 | $this->peerAssessment = $peerAssessment; |
||
403 | |||
404 | return $this; |
||
405 | } |
||
406 | |||
407 | public function getAllowCoachChangeOptionsGroups(): bool |
||
408 | { |
||
409 | return $this->allowCoachChangeOptionsGroups; |
||
410 | } |
||
411 | |||
412 | public function setAllowCoachChangeOptionsGroups(bool $allowCoachChangeOptionsGroups): self |
||
413 | { |
||
414 | $this->allowCoachChangeOptionsGroups = $allowCoachChangeOptionsGroups; |
||
415 | |||
416 | return $this; |
||
417 | } |
||
418 | |||
419 | public function getAllowChangeGroupName(): ?int |
||
420 | { |
||
421 | return $this->allowChangeGroupName; |
||
422 | } |
||
423 | |||
424 | public function setAllowChangeGroupName(?int $allowChangeGroupName): self |
||
425 | { |
||
426 | $this->allowChangeGroupName = $allowChangeGroupName; |
||
427 | |||
428 | return $this; |
||
429 | } |
||
430 | |||
431 | public function getAllowAutogroup(): bool |
||
432 | { |
||
433 | return $this->allowAutogroup; |
||
434 | } |
||
435 | |||
436 | public function setAllowAutogroup(bool $allowAutogroup): self |
||
437 | { |
||
438 | $this->allowAutogroup = $allowAutogroup; |
||
439 | |||
440 | return $this; |
||
441 | } |
||
442 | |||
443 | public function getResourceIdentifier(): int|Uuid |
||
444 | { |
||
445 | return $this->iid; |
||
|
|||
446 | } |
||
447 | |||
448 | public function getResourceName(): string |
||
451 | } |
||
452 | |||
453 | public function setResourceName(string $name): self |
||
454 | { |
||
455 | return $this->setTitle($name); |
||
456 | } |
||
457 | } |
||
458 |