Complex classes like PageSeoTranslation 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 PageSeoTranslation, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class PageSeoTranslation |
||
18 | { |
||
19 | use Translation; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | * |
||
24 | * @ORM\Column(name="meta_title", type="string", nullable=true) |
||
25 | * @Assert\Length(max = 60) |
||
26 | */ |
||
27 | protected $metaTitle; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | * |
||
32 | * @ORM\Column(name="meta_description", type="string", length=255, nullable=true) |
||
33 | * @Assert\Length(max = 155) |
||
34 | */ |
||
35 | protected $metaDescription; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | * |
||
40 | * @ORM\Column(name="rel_author", type="string", length=255, nullable=true) |
||
41 | */ |
||
42 | protected $relAuthor; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | * |
||
47 | * @ORM\Column(name="rel_publisher", type="string", length=255, nullable=true) |
||
48 | */ |
||
49 | protected $relPublisher; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | * |
||
54 | * @ORM\Column(name="ogTitle", type="string", length=255, nullable=true) |
||
55 | */ |
||
56 | protected $ogTitle; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | * |
||
61 | * @ORM\Column(name="ogType", type="string", length=255, nullable=true) |
||
62 | */ |
||
63 | protected $ogType; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | * |
||
68 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
69 | * @ORM\JoinColumn(name="ogImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
70 | */ |
||
71 | protected $ogImage; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | * |
||
76 | * @ORM\Column(name="ogUrl", type="string", length=255, nullable=true) |
||
77 | */ |
||
78 | protected $ogUrl; |
||
79 | |||
80 | /** |
||
81 | * @var text |
||
82 | * |
||
83 | * @ORM\Column(name="ogDescription", type="text", nullable=true) |
||
84 | */ |
||
85 | protected $ogDescription; |
||
86 | |||
87 | /** |
||
88 | * @var string |
||
89 | * |
||
90 | * @ORM\Column(name="fbAdmins", type="string", length=255, nullable=true) |
||
91 | */ |
||
92 | protected $fbAdmins; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | * |
||
97 | * @ORM\Column(name="twitterCard", type="string", length=255, nullable=true) |
||
98 | */ |
||
99 | protected $twitterCard = 'summary'; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | * |
||
104 | * @ORM\Column(name="twitterUrl", type="string", length=255, nullable=true) |
||
105 | * @Assert\Length(max = 15) |
||
106 | */ |
||
107 | protected $twitterUrl; |
||
108 | |||
109 | /** |
||
110 | * @var string |
||
111 | * |
||
112 | * @ORM\Column(name="twitterCreator", type="string", length=255, nullable=true) |
||
113 | * @Assert\Length(max = 15) |
||
114 | */ |
||
115 | protected $twitterCreator; |
||
116 | |||
117 | /** |
||
118 | * @var string |
||
119 | * |
||
120 | * @ORM\Column(name="twitterTitle", type="string", length=255, nullable=true) |
||
121 | * @Assert\Length(max = 70) |
||
122 | */ |
||
123 | protected $twitterTitle; |
||
124 | |||
125 | /** |
||
126 | * @var string |
||
127 | * |
||
128 | * @ORM\Column(name="twitterDescription", type="string", length=255, nullable=true) |
||
129 | * @Assert\Length(max = 200) |
||
130 | */ |
||
131 | protected $twitterDescription; |
||
132 | |||
133 | /** |
||
134 | * @var string |
||
135 | * |
||
136 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
137 | * @ORM\JoinColumn(name="twitterImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
138 | */ |
||
139 | protected $twitterImage; |
||
140 | |||
141 | /** |
||
142 | * @var string |
||
143 | * |
||
144 | * @ORM\Column(name="schemaPageType", type="string", length=255, nullable=true) |
||
145 | */ |
||
146 | protected $schemaPageType; |
||
147 | |||
148 | /** |
||
149 | * @var string |
||
150 | * |
||
151 | * @ORM\Column(name="schemaName", type="string", length=255, nullable=true) |
||
152 | */ |
||
153 | protected $schemaName; |
||
154 | |||
155 | /** |
||
156 | * @var string |
||
157 | * |
||
158 | * @ORM\Column(name="schemaDescription", type="string", length=255, nullable=true) |
||
159 | */ |
||
160 | protected $schemaDescription; |
||
161 | |||
162 | /** |
||
163 | * @var string |
||
164 | * |
||
165 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
166 | * @ORM\JoinColumn(name="schemaImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
167 | */ |
||
168 | protected $schemaImage; |
||
169 | |||
170 | /** |
||
171 | * @var string |
||
172 | * |
||
173 | * @ORM\Column(name="meta_robots_index", type="string", length=255, nullable=true) |
||
174 | */ |
||
175 | protected $metaRobotsIndex; |
||
176 | |||
177 | /** |
||
178 | * @var string |
||
179 | * |
||
180 | * @ORM\Column(name="meta_robots_follow", type="string", length=255, nullable=true) |
||
181 | */ |
||
182 | protected $metaRobotsFollow; |
||
183 | |||
184 | /** |
||
185 | * @var string |
||
186 | * |
||
187 | * @ORM\Column(name="meta_robots_advanced", type="string", length=255, nullable=true) |
||
188 | */ |
||
189 | protected $metaRobotsAdvanced; |
||
190 | |||
191 | /** |
||
192 | * @var bool |
||
193 | * |
||
194 | * @ORM\Column(name="sitemap_indexed", type="boolean", nullable=true, options={"default" = true}) |
||
195 | */ |
||
196 | protected $sitemapIndexed = true; |
||
197 | |||
198 | /** |
||
199 | * @var float |
||
200 | * |
||
201 | * @ORM\Column(name="sitemap_priority", type="float", nullable=true, options={"default" = "0.8"}) |
||
202 | */ |
||
203 | protected $sitemapPriority = 0.8; |
||
204 | |||
205 | /** |
||
206 | * @var string |
||
207 | * |
||
208 | * @ORM\Column(name="sitemap_changeFreq", type="string", length=20, nullable=true, options={"default" = "monthly"}) |
||
209 | */ |
||
210 | protected $sitemapChangeFreq = 'monthly'; |
||
211 | |||
212 | /** |
||
213 | * @var string |
||
214 | * |
||
215 | * @ORM\Column(name="rel_canonical", type="string", length=255, nullable=true) |
||
216 | */ |
||
217 | protected $relCanonical; |
||
218 | |||
219 | /** |
||
220 | * @var string |
||
221 | * |
||
222 | * @ORM\Column(name="keyword", type="string", length=255, nullable=true) |
||
223 | */ |
||
224 | protected $keyword; |
||
225 | |||
226 | /** |
||
227 | * @var string |
||
228 | * |
||
229 | * @ORM\ManyToOne(targetEntity="Victoire\Bundle\CoreBundle\Entity\Link", inversedBy="referers", cascade={"persist"}) |
||
230 | * @ORM\JoinColumn(name="redirect_to", referencedColumnName="id", onDelete="SET NULL") |
||
231 | */ |
||
232 | protected $redirectTo; |
||
233 | |||
234 | /** |
||
235 | * Get id. |
||
236 | * |
||
237 | * @return int |
||
238 | */ |
||
239 | public function getId() |
||
243 | |||
244 | /** |
||
245 | * Set redirectTo. |
||
246 | * |
||
247 | * @param View $redirectTo |
||
248 | * |
||
249 | * @return PageSeo |
||
250 | */ |
||
251 | public function setRedirectTo(Link $redirectTo) |
||
257 | |||
258 | /** |
||
259 | * Get redirectTo. |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | public function getRedirectTo() |
||
267 | |||
268 | /** |
||
269 | * Set metaTitle. |
||
270 | * |
||
271 | * @param string $metaTitle |
||
272 | * |
||
273 | * @return PageSeo |
||
274 | */ |
||
275 | public function setMetaTitle($metaTitle) |
||
281 | |||
282 | /** |
||
283 | * Get metaTitle. |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | public function getMetaTitle() |
||
291 | |||
292 | /** |
||
293 | * Set metaDescription. |
||
294 | * |
||
295 | * @param string $metaDescription |
||
296 | * |
||
297 | * @return PageSeo |
||
298 | */ |
||
299 | public function setMetaDescription($metaDescription) |
||
305 | |||
306 | /** |
||
307 | * Get metaDescription. |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | public function getMetaDescription() |
||
315 | |||
316 | /** |
||
317 | * Set relAuthor. |
||
318 | * |
||
319 | * @param string $relAuthor |
||
320 | * |
||
321 | * @return PageSeo |
||
322 | */ |
||
323 | public function setRelAuthor($relAuthor) |
||
329 | |||
330 | /** |
||
331 | * Get relAuthor. |
||
332 | * |
||
333 | * @return string |
||
334 | */ |
||
335 | public function getRelAuthor() |
||
339 | |||
340 | /** |
||
341 | * Set relPublisher. |
||
342 | * |
||
343 | * @param string $relPublisher |
||
344 | * |
||
345 | * @return PageSeo |
||
346 | */ |
||
347 | public function setRelPublisher($relPublisher) |
||
353 | |||
354 | /** |
||
355 | * Get relPublisher. |
||
356 | * |
||
357 | * @return string |
||
358 | */ |
||
359 | public function getRelPublisher() |
||
363 | |||
364 | /** |
||
365 | * Set ogTitle. |
||
366 | * |
||
367 | * @param string $ogTitle |
||
368 | * |
||
369 | * @return PageSeo |
||
370 | */ |
||
371 | public function setOgTitle($ogTitle) |
||
377 | |||
378 | /** |
||
379 | * Get ogTitle. |
||
380 | * |
||
381 | * @return string |
||
382 | */ |
||
383 | public function getOgTitle() |
||
387 | |||
388 | /** |
||
389 | * Set ogType. |
||
390 | * |
||
391 | * @param string $ogType |
||
392 | * |
||
393 | * @return PageSeo |
||
394 | */ |
||
395 | public function setOgType($ogType) |
||
401 | |||
402 | /** |
||
403 | * Get ogType. |
||
404 | * |
||
405 | * @return string |
||
406 | */ |
||
407 | public function getOgType() |
||
411 | |||
412 | /** |
||
413 | * Set ogImage. |
||
414 | * |
||
415 | * @param Image $ogImage |
||
416 | * |
||
417 | * @return PageSeo |
||
418 | */ |
||
419 | public function setOgImage($ogImage) |
||
425 | |||
426 | /** |
||
427 | * Get ogImage. |
||
428 | * |
||
429 | * @return string |
||
430 | */ |
||
431 | public function getOgImage() |
||
435 | |||
436 | /** |
||
437 | * Set ogUrl. |
||
438 | * |
||
439 | * @param string $ogUrl |
||
440 | * |
||
441 | * @return PageSeo |
||
442 | */ |
||
443 | public function setOgUrl($ogUrl) |
||
449 | |||
450 | /** |
||
451 | * Get ogUrl. |
||
452 | * |
||
453 | * @return string |
||
454 | */ |
||
455 | public function getOgUrl() |
||
459 | |||
460 | /** |
||
461 | * Set ogDescription. |
||
462 | * |
||
463 | * @param string $ogDescription |
||
464 | * |
||
465 | * @return PageSeo |
||
466 | */ |
||
467 | public function setOgDescription($ogDescription) |
||
473 | |||
474 | /** |
||
475 | * Get ogDescription. |
||
476 | * |
||
477 | * @return string |
||
478 | */ |
||
479 | public function getOgDescription() |
||
483 | |||
484 | /** |
||
485 | * Set fbAdmins. |
||
486 | * |
||
487 | * @param string $fbAdmins |
||
488 | * |
||
489 | * @return PageSeo |
||
490 | */ |
||
491 | public function setFbAdmins($fbAdmins) |
||
497 | |||
498 | /** |
||
499 | * Get fbAdmins. |
||
500 | * |
||
501 | * @return string |
||
502 | */ |
||
503 | public function getFbAdmins() |
||
507 | |||
508 | /** |
||
509 | * Set twitterCard. |
||
510 | * |
||
511 | * @param string $twitterCard |
||
512 | * |
||
513 | * @return PageSeo |
||
514 | */ |
||
515 | public function setTwitterCard($twitterCard) |
||
521 | |||
522 | /** |
||
523 | * Get twitterCard. |
||
524 | * |
||
525 | * @return string |
||
526 | */ |
||
527 | public function getTwitterCard() |
||
531 | |||
532 | /** |
||
533 | * Set twitterUrl. |
||
534 | * |
||
535 | * @param string $twitterUrl |
||
536 | * |
||
537 | * @return PageSeo |
||
538 | */ |
||
539 | public function setTwitterUrl($twitterUrl) |
||
545 | |||
546 | /** |
||
547 | * Get twitterUrl. |
||
548 | * |
||
549 | * @return string |
||
550 | */ |
||
551 | public function getTwitterUrl() |
||
555 | |||
556 | /** |
||
557 | * Set twitterCreator. |
||
558 | * |
||
559 | * @param string $twitterCreator |
||
560 | * |
||
561 | * @return PageSeo |
||
562 | */ |
||
563 | public function setTwitterCreator($twitterCreator) |
||
569 | |||
570 | /** |
||
571 | * Get twitterCreator. |
||
572 | * |
||
573 | * @return string |
||
574 | */ |
||
575 | public function getTwitterCreator() |
||
579 | |||
580 | /** |
||
581 | * Set twitterTitle. |
||
582 | * |
||
583 | * @param string $twitterTitle |
||
584 | * |
||
585 | * @return PageSeo |
||
586 | */ |
||
587 | public function setTwitterTitle($twitterTitle) |
||
593 | |||
594 | /** |
||
595 | * Get twitterTitle. |
||
596 | * |
||
597 | * @return string |
||
598 | */ |
||
599 | public function getTwitterTitle() |
||
603 | |||
604 | /** |
||
605 | * Set twitterDescription. |
||
606 | * |
||
607 | * @param string $twitterDescription |
||
608 | * |
||
609 | * @return PageSeo |
||
610 | */ |
||
611 | public function setTwitterDescription($twitterDescription) |
||
617 | |||
618 | /** |
||
619 | * Get twitterDescription. |
||
620 | * |
||
621 | * @return string |
||
622 | */ |
||
623 | public function getTwitterDescription() |
||
627 | |||
628 | /** |
||
629 | * Set twitterImage. |
||
630 | * |
||
631 | * @param Image $twitterImage |
||
632 | * |
||
633 | * @return PageSeo |
||
634 | */ |
||
635 | public function setTwitterImage($twitterImage) |
||
641 | |||
642 | /** |
||
643 | * Get twitterImage. |
||
644 | * |
||
645 | * @return string |
||
646 | */ |
||
647 | public function getTwitterImage() |
||
651 | |||
652 | /** |
||
653 | * Set schemaPageType. |
||
654 | * |
||
655 | * @param string $schemaPageType |
||
656 | * |
||
657 | * @return PageSeo |
||
658 | */ |
||
659 | public function setSchemaPageType($schemaPageType) |
||
665 | |||
666 | /** |
||
667 | * Get schemaPageType. |
||
668 | * |
||
669 | * @return string |
||
670 | */ |
||
671 | public function getSchemaPageType() |
||
675 | |||
676 | /** |
||
677 | * Set schemaName. |
||
678 | * |
||
679 | * @param string $schemaName |
||
680 | * |
||
681 | * @return PageSeo |
||
682 | */ |
||
683 | public function setSchemaName($schemaName) |
||
689 | |||
690 | /** |
||
691 | * Get schemaName. |
||
692 | * |
||
693 | * @return string |
||
694 | */ |
||
695 | public function getSchemaName() |
||
699 | |||
700 | /** |
||
701 | * Set schemaDescription. |
||
702 | * |
||
703 | * @param string $schemaDescription |
||
704 | * |
||
705 | * @return PageSeo |
||
706 | */ |
||
707 | public function setSchemaDescription($schemaDescription) |
||
713 | |||
714 | /** |
||
715 | * Get schemaDescription. |
||
716 | * |
||
717 | * @return string |
||
718 | */ |
||
719 | public function getSchemaDescription() |
||
723 | |||
724 | /** |
||
725 | * Set schemaImage. |
||
726 | * |
||
727 | * @param Image $schemaImage |
||
728 | * |
||
729 | * @return PageSeo |
||
730 | */ |
||
731 | public function setSchemaImage($schemaImage) |
||
737 | |||
738 | /** |
||
739 | * Get schemaImage. |
||
740 | * |
||
741 | * @return string |
||
742 | */ |
||
743 | public function getSchemaImage() |
||
747 | |||
748 | /** |
||
749 | * Set metaRobotsIndex. |
||
750 | * |
||
751 | * @param string $metaRobotsIndex |
||
752 | * |
||
753 | * @return PageSeo |
||
754 | */ |
||
755 | public function setMetaRobotsIndex($metaRobotsIndex) |
||
761 | |||
762 | /** |
||
763 | * Get metaRobotsIndex. |
||
764 | * |
||
765 | * @return string |
||
766 | */ |
||
767 | public function getMetaRobotsIndex() |
||
771 | |||
772 | /** |
||
773 | * Set metaRobotsFollow. |
||
774 | * |
||
775 | * @param string $metaRobotsFollow |
||
776 | * |
||
777 | * @return PageSeo |
||
778 | */ |
||
779 | public function setMetaRobotsFollow($metaRobotsFollow) |
||
785 | |||
786 | /** |
||
787 | * Get metaRobotsFollow. |
||
788 | * |
||
789 | * @return string |
||
790 | */ |
||
791 | public function getMetaRobotsFollow() |
||
795 | |||
796 | /** |
||
797 | * Set metaRobotsAdvanced. |
||
798 | * |
||
799 | * @param string $metaRobotsAdvanced |
||
800 | * |
||
801 | * @return PageSeo |
||
802 | */ |
||
803 | public function setMetaRobotsAdvanced($metaRobotsAdvanced) |
||
809 | |||
810 | /** |
||
811 | * Get metaRobotsAdvanced. |
||
812 | * |
||
813 | * @return string |
||
814 | */ |
||
815 | public function getMetaRobotsAdvanced() |
||
819 | |||
820 | /** |
||
821 | * Set sitemapIndexed. |
||
822 | * |
||
823 | * @param bool $sitemapIndexed |
||
824 | * |
||
825 | * @return PageSeo |
||
826 | */ |
||
827 | public function setSitemapIndexed($sitemapIndexed) |
||
833 | |||
834 | /** |
||
835 | * Get sitemapIndexed. |
||
836 | * |
||
837 | * @return bool |
||
838 | */ |
||
839 | public function isSitemapIndexed() |
||
843 | |||
844 | /** |
||
845 | * Set sitemapPriority. |
||
846 | * |
||
847 | * @param float $sitemapPriority |
||
848 | * |
||
849 | * @return PageSeo |
||
850 | */ |
||
851 | public function setSitemapPriority($sitemapPriority) |
||
857 | |||
858 | /** |
||
859 | * Get sitemapPriority. |
||
860 | * |
||
861 | * @return float |
||
862 | */ |
||
863 | public function getSitemapPriority() |
||
867 | |||
868 | /** |
||
869 | * Set sitemapChangeFreq. |
||
870 | * |
||
871 | * @param float $sitemapChangeFreq |
||
872 | * |
||
873 | * @return PageSeo |
||
874 | */ |
||
875 | public function setSitemapChangeFreq($sitemapChangeFreq) |
||
881 | |||
882 | /** |
||
883 | * Get sitemapChangeFreq. |
||
884 | * |
||
885 | * @return float |
||
886 | */ |
||
887 | public function getSitemapChangeFreq() |
||
891 | |||
892 | /** |
||
893 | * Set relCanonical. |
||
894 | * |
||
895 | * @param string $relCanonical |
||
896 | * |
||
897 | * @return PageSeo |
||
898 | */ |
||
899 | public function setRelCanonical($relCanonical) |
||
905 | |||
906 | /** |
||
907 | * Get relCanonical. |
||
908 | * |
||
909 | * @return string |
||
910 | */ |
||
911 | public function getRelCanonical() |
||
915 | |||
916 | /** |
||
917 | * Set keyword. |
||
918 | * |
||
919 | * @param string $keyword |
||
920 | * |
||
921 | * @return PageSeo |
||
922 | */ |
||
923 | public function setKeyword($keyword) |
||
929 | |||
930 | /** |
||
931 | * Get keyword. |
||
932 | * |
||
933 | * @return string |
||
934 | */ |
||
935 | public function getKeyword() |
||
939 | } |
||
940 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..