Complex classes like Seo 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Seo, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Seo extends AbstractEntity |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | * |
||
24 | * @ORM\Column(name="meta_title", type="string", nullable=true) |
||
25 | * |
||
26 | */ |
||
27 | protected $metaTitle; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | * |
||
32 | * @ORM\Column(name="meta_description", type="text", nullable=true) |
||
33 | * |
||
34 | */ |
||
35 | protected $metaDescription; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | * |
||
40 | * @ORM\Column(name="meta_author", type="string", nullable=true) |
||
41 | */ |
||
42 | protected $metaAuthor; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | * |
||
47 | * @ORM\Column(name="meta_robots", type="string", nullable=true) |
||
48 | */ |
||
49 | protected $metaRobots; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | * |
||
54 | * @ORM\Column(name="og_type", type="string", nullable=true) |
||
55 | */ |
||
56 | protected $ogType; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | * |
||
61 | * @ORM\Column(name="og_title", type="string", nullable=true) |
||
62 | */ |
||
63 | protected $ogTitle; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | * |
||
68 | * @ORM\Column(name="og_description", type="text", nullable=true) |
||
69 | */ |
||
70 | protected $ogDescription; |
||
71 | |||
72 | /** |
||
73 | * @var Media |
||
74 | * |
||
75 | * @ORM\ManyToOne(targetEntity="Kunstmaan\MediaBundle\Entity\Media") |
||
76 | * @ORM\JoinColumn(name="og_image_id", referencedColumnName="id") |
||
77 | */ |
||
78 | protected $ogImage; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | * |
||
83 | * @ORM\Column(name="extra_metadata", type="text", nullable=true) |
||
84 | */ |
||
85 | protected $extraMetadata; |
||
86 | |||
87 | /** |
||
88 | * @var int |
||
89 | * |
||
90 | * @ORM\Column(type="bigint", name="ref_id") |
||
91 | */ |
||
92 | protected $refId; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | * |
||
97 | * @ORM\Column(type="string", name="ref_entity_name") |
||
98 | */ |
||
99 | protected $refEntityName; |
||
100 | |||
101 | /** |
||
102 | * @ORM\Column(type="string", nullable=true, name="og_url") |
||
103 | */ |
||
104 | protected $ogUrl; |
||
105 | |||
106 | /** |
||
107 | * @ORM\Column(type="string", length=100, nullable=true, name="og_article_author") |
||
108 | */ |
||
109 | protected $ogArticleAuthor; |
||
110 | |||
111 | /** |
||
112 | * @ORM\Column(type="string", length=100, nullable=true, name="og_article_publisher") |
||
113 | */ |
||
114 | protected $ogArticlePublisher; |
||
115 | |||
116 | /** |
||
117 | * @ORM\Column(type="string", length=100, nullable=true, name="og_article_section") |
||
118 | */ |
||
119 | protected $ogArticleSection; |
||
120 | |||
121 | /** |
||
122 | * @var string $twitterTitle |
||
123 | * |
||
124 | * @ORM\Column(name="twitter_title", type="string", length=255, nullable=true) |
||
125 | */ |
||
126 | protected $twitterTitle; |
||
127 | |||
128 | /** |
||
129 | * @var string $twitterTitle |
||
130 | * |
||
131 | * @ORM\Column(name="twitter_description", type="text", nullable=true) |
||
132 | */ |
||
133 | protected $twitterDescription; |
||
134 | |||
135 | /** |
||
136 | * @var string $twitterTitle |
||
137 | * |
||
138 | * @ORM\Column(name="twitter_site", type="string", length=255, nullable=true) |
||
139 | */ |
||
140 | protected $twitterSite; |
||
141 | |||
142 | /** |
||
143 | * @var string $twitterTitle |
||
144 | * |
||
145 | * @ORM\Column(name="twitter_creator", type="string", length=255, nullable=true) |
||
146 | */ |
||
147 | protected $twitterCreator; |
||
148 | |||
149 | /** |
||
150 | * @var Media |
||
151 | * |
||
152 | * @ORM\ManyToOne(targetEntity="Kunstmaan\MediaBundle\Entity\Media") |
||
153 | * @ORM\JoinColumn(name="twitter_image_id", referencedColumnName="id") |
||
154 | */ |
||
155 | protected $twitterImage; |
||
156 | |||
157 | /** |
||
158 | * @param string $url |
||
159 | * |
||
160 | * @return Seo |
||
161 | */ |
||
162 | public function setOgUrl($url) |
||
168 | |||
169 | /** |
||
170 | * @return string |
||
171 | */ |
||
172 | public function getOgUrl() |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getMetaTitle() |
||
184 | |||
185 | /** |
||
186 | * @param string $title |
||
187 | * |
||
188 | * @return string |
||
|
|||
189 | */ |
||
190 | public function setMetaTitle($title) |
||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getMetaAuthor() |
||
204 | |||
205 | /** |
||
206 | * @param string $meta |
||
207 | * |
||
208 | * @return Seo |
||
209 | */ |
||
210 | public function setMetaAuthor($meta) |
||
216 | |||
217 | /** |
||
218 | * @return string |
||
219 | */ |
||
220 | public function getMetaDescription() |
||
224 | |||
225 | /** |
||
226 | * @param string $meta |
||
227 | * |
||
228 | * @return Seo |
||
229 | */ |
||
230 | public function setMetaDescription($meta) |
||
236 | |||
237 | /** |
||
238 | * @return string |
||
239 | */ |
||
240 | public function getMetaRobots() |
||
244 | |||
245 | /** |
||
246 | * @param string $meta |
||
247 | * |
||
248 | * @return Seo |
||
249 | */ |
||
250 | public function setMetaRobots($meta) |
||
256 | |||
257 | /** |
||
258 | * @return string |
||
259 | */ |
||
260 | public function getExtraMetadata() |
||
264 | |||
265 | /** |
||
266 | * @param string $extraMetadata |
||
267 | * |
||
268 | * @return Seo |
||
269 | */ |
||
270 | public function setExtraMetadata($extraMetadata) |
||
276 | |||
277 | /** |
||
278 | * @param string $ogDescription |
||
279 | * |
||
280 | * @return Seo |
||
281 | */ |
||
282 | public function setOgDescription($ogDescription) |
||
288 | |||
289 | /** |
||
290 | * @return mixed |
||
291 | */ |
||
292 | public function getOgDescription() |
||
296 | |||
297 | /** |
||
298 | * @param Media $ogImage |
||
299 | * |
||
300 | * @return Seo |
||
301 | */ |
||
302 | public function setOgImage(Media $ogImage = null) |
||
308 | |||
309 | /** |
||
310 | * @return mixed |
||
311 | */ |
||
312 | public function getOgImage() |
||
316 | |||
317 | /** |
||
318 | * @param string $ogTitle |
||
319 | * |
||
320 | * @return Seo |
||
321 | */ |
||
322 | public function setOgTitle($ogTitle) |
||
328 | |||
329 | /** |
||
330 | * @return mixed |
||
331 | */ |
||
332 | public function getOgTitle() |
||
336 | |||
337 | /** |
||
338 | * @param string $ogType |
||
339 | * |
||
340 | * @return Seo |
||
341 | */ |
||
342 | public function setOgType($ogType) |
||
348 | |||
349 | /** |
||
350 | * @return mixed |
||
351 | */ |
||
352 | public function getOgType() |
||
356 | |||
357 | /** |
||
358 | * @return mixed |
||
359 | */ |
||
360 | public function getOgArticleAuthor() |
||
364 | |||
365 | /** |
||
366 | * @param mixed $ogArticleAuthor |
||
367 | */ |
||
368 | public function setOgArticleAuthor($ogArticleAuthor) |
||
372 | |||
373 | /** |
||
374 | * @return mixed |
||
375 | */ |
||
376 | public function getOgArticlePublisher() |
||
380 | |||
381 | /** |
||
382 | * @param mixed $ogArticlePublisher |
||
383 | */ |
||
384 | public function setOgArticlePublisher($ogArticlePublisher) |
||
388 | |||
389 | /** |
||
390 | * @return mixed |
||
391 | */ |
||
392 | public function getOgArticleSection() |
||
396 | |||
397 | /** |
||
398 | * @param mixed $ogArticleSection |
||
399 | */ |
||
400 | public function setOgArticleSection($ogArticleSection) |
||
404 | |||
405 | /** |
||
406 | * @return string |
||
407 | */ |
||
408 | public function getTwitterTitle() |
||
412 | |||
413 | /** |
||
414 | * @param string $twitterTitle |
||
415 | */ |
||
416 | public function setTwitterTitle($twitterTitle) |
||
420 | |||
421 | /** |
||
422 | * @return string |
||
423 | */ |
||
424 | public function getTwitterDescription() |
||
428 | |||
429 | /** |
||
430 | * @param string $twitterDescription |
||
431 | */ |
||
432 | public function setTwitterDescription($twitterDescription) |
||
436 | |||
437 | /** |
||
438 | * @return string |
||
439 | */ |
||
440 | public function getTwitterSite() |
||
444 | |||
445 | /** |
||
446 | * @param string $twitterSite |
||
447 | */ |
||
448 | public function setTwitterSite($twitterSite) |
||
452 | |||
453 | /** |
||
454 | * @return string |
||
455 | */ |
||
456 | public function getTwitterCreator() |
||
460 | |||
461 | /** |
||
462 | * @param string $twitterCreator |
||
463 | */ |
||
464 | public function setTwitterCreator($twitterCreator) |
||
468 | |||
469 | /** |
||
470 | * @return Media |
||
471 | */ |
||
472 | public function getTwitterImage() |
||
476 | |||
477 | /** |
||
478 | * @param Media $twitterImage |
||
479 | */ |
||
480 | public function setTwitterImage($twitterImage) |
||
484 | |||
485 | /** |
||
486 | * Get refId |
||
487 | * |
||
488 | * @return int |
||
489 | */ |
||
490 | public function getRefId() |
||
494 | |||
495 | /** |
||
496 | * Set refId |
||
497 | * |
||
498 | * @param int $refId |
||
499 | * |
||
500 | * @return Seo |
||
501 | */ |
||
502 | protected function setRefId($refId) |
||
508 | |||
509 | /** |
||
510 | * Set reference entity name |
||
511 | * |
||
512 | * @param string $refEntityName |
||
513 | * |
||
514 | * @return Seo |
||
515 | */ |
||
516 | protected function setRefEntityName($refEntityName) |
||
522 | |||
523 | /** |
||
524 | * Get reference entity name |
||
525 | * |
||
526 | * @return string |
||
527 | */ |
||
528 | public function getRefEntityName() |
||
532 | |||
533 | /** |
||
534 | * @param AbstractEntity $entity |
||
535 | * |
||
536 | * @return Seo |
||
537 | */ |
||
538 | public function setRef(AbstractEntity $entity) |
||
545 | |||
546 | /** |
||
547 | * @param EntityManager $em |
||
548 | * |
||
549 | * @return AbstractEntity |
||
550 | */ |
||
551 | public function getRef(EntityManager $em) |
||
555 | |||
556 | /** |
||
557 | * @return string |
||
558 | */ |
||
559 | public function getDefaultAdminType() |
||
563 | } |
||
564 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.