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 | const SITEMAP_INDEXED_DEFAULT = true; |
||
20 | const SITEMAP_PRIORITY_DEFAULT = 0.5; |
||
21 | |||
22 | use Translation; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | * |
||
27 | * @ORM\Column(name="meta_title", type="string", nullable=true) |
||
28 | * @Assert\Length(max = 65) |
||
29 | */ |
||
30 | protected $metaTitle; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | * |
||
35 | * @ORM\Column(name="meta_description", type="string", length=255, nullable=true) |
||
36 | * @Assert\Length(max = 155) |
||
37 | */ |
||
38 | protected $metaDescription; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | * |
||
43 | * @ORM\Column(name="rel_author", type="string", length=255, nullable=true) |
||
44 | */ |
||
45 | protected $relAuthor; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | * |
||
50 | * @ORM\Column(name="rel_publisher", type="string", length=255, nullable=true) |
||
51 | */ |
||
52 | protected $relPublisher; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | * |
||
57 | * @ORM\Column(name="ogTitle", type="string", length=255, nullable=true) |
||
58 | */ |
||
59 | protected $ogTitle; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | * |
||
64 | * @ORM\Column(name="ogType", type="string", length=255, nullable=true) |
||
65 | */ |
||
66 | protected $ogType; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | * |
||
71 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
72 | * @ORM\JoinColumn(name="ogImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
73 | */ |
||
74 | protected $ogImage; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | * |
||
79 | * @ORM\Column(name="ogUrl", type="string", length=255, nullable=true) |
||
80 | */ |
||
81 | protected $ogUrl; |
||
82 | |||
83 | /** |
||
84 | * @var text |
||
85 | * |
||
86 | * @ORM\Column(name="ogDescription", type="text", nullable=true) |
||
87 | */ |
||
88 | protected $ogDescription; |
||
89 | |||
90 | /** |
||
91 | * @var string |
||
92 | * |
||
93 | * @ORM\Column(name="fbAdmins", type="string", length=255, nullable=true) |
||
94 | */ |
||
95 | protected $fbAdmins; |
||
96 | |||
97 | /** |
||
98 | * @var string |
||
99 | * |
||
100 | * @ORM\Column(name="twitterCard", type="string", length=255, nullable=true) |
||
101 | */ |
||
102 | protected $twitterCard = 'summary'; |
||
103 | |||
104 | /** |
||
105 | * @var string |
||
106 | * |
||
107 | * @ORM\Column(name="twitterUrl", type="string", length=255, nullable=true) |
||
108 | * @Assert\Length(max = 15) |
||
109 | */ |
||
110 | protected $twitterUrl; |
||
111 | |||
112 | /** |
||
113 | * @var string |
||
114 | * |
||
115 | * @ORM\Column(name="twitterCreator", type="string", length=255, nullable=true) |
||
116 | * @Assert\Length(max = 15) |
||
117 | */ |
||
118 | protected $twitterCreator; |
||
119 | |||
120 | /** |
||
121 | * @var string |
||
122 | * |
||
123 | * @ORM\Column(name="twitterTitle", type="string", length=255, nullable=true) |
||
124 | * @Assert\Length(max = 70) |
||
125 | */ |
||
126 | protected $twitterTitle; |
||
127 | |||
128 | /** |
||
129 | * @var string |
||
130 | * |
||
131 | * @ORM\Column(name="twitterDescription", type="string", length=255, nullable=true) |
||
132 | * @Assert\Length(max = 200) |
||
133 | */ |
||
134 | protected $twitterDescription; |
||
135 | |||
136 | /** |
||
137 | * @var string |
||
138 | * |
||
139 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
140 | * @ORM\JoinColumn(name="twitterImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
141 | */ |
||
142 | protected $twitterImage; |
||
143 | |||
144 | /** |
||
145 | * @var string |
||
146 | * |
||
147 | * @ORM\Column(name="schemaPageType", type="string", length=255, nullable=true) |
||
148 | */ |
||
149 | protected $schemaPageType; |
||
150 | |||
151 | /** |
||
152 | * @var string |
||
153 | * |
||
154 | * @ORM\Column(name="schemaName", type="string", length=255, nullable=true) |
||
155 | */ |
||
156 | protected $schemaName; |
||
157 | |||
158 | /** |
||
159 | * @var string |
||
160 | * |
||
161 | * @ORM\Column(name="schemaDescription", type="string", length=255, nullable=true) |
||
162 | */ |
||
163 | protected $schemaDescription; |
||
164 | |||
165 | /** |
||
166 | * @var string |
||
167 | * |
||
168 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
169 | * @ORM\JoinColumn(name="schemaImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
170 | */ |
||
171 | protected $schemaImage; |
||
172 | |||
173 | /** |
||
174 | * @var string |
||
175 | * |
||
176 | * @ORM\Column(name="meta_robots_index", type="string", length=255, nullable=true) |
||
177 | */ |
||
178 | protected $metaRobotsIndex; |
||
179 | |||
180 | /** |
||
181 | * @var string |
||
182 | * |
||
183 | * @ORM\Column(name="meta_robots_follow", type="string", length=255, nullable=true) |
||
184 | */ |
||
185 | protected $metaRobotsFollow; |
||
186 | |||
187 | /** |
||
188 | * @var string |
||
189 | * |
||
190 | * @ORM\Column(name="meta_robots_advanced", type="string", length=255, nullable=true) |
||
191 | */ |
||
192 | protected $metaRobotsAdvanced; |
||
193 | |||
194 | /** |
||
195 | * @var bool |
||
196 | * |
||
197 | * @ORM\Column(name="sitemap_indexed", type="boolean", nullable=true, options={"default" = true}) |
||
198 | */ |
||
199 | protected $sitemapIndexed = self::SITEMAP_INDEXED_DEFAULT; |
||
200 | |||
201 | /** |
||
202 | * @var float |
||
203 | * |
||
204 | * @ORM\Column(name="sitemap_priority", type="float", nullable=true, options={"default" = "0.5"}) |
||
205 | */ |
||
206 | protected $sitemapPriority = self::SITEMAP_PRIORITY_DEFAULT; |
||
207 | |||
208 | /** |
||
209 | * @var string |
||
210 | * |
||
211 | * @ORM\Column(name="sitemap_changeFreq", type="string", length=20, nullable=true, options={"default" = "monthly"}) |
||
212 | */ |
||
213 | protected $sitemapChangeFreq = 'monthly'; |
||
214 | |||
215 | /** |
||
216 | * @var string |
||
217 | * |
||
218 | * @ORM\Column(name="rel_canonical", type="string", length=255, nullable=true) |
||
219 | */ |
||
220 | protected $relCanonical; |
||
221 | |||
222 | /** |
||
223 | * @var string |
||
224 | * |
||
225 | * @ORM\Column(name="keyword", type="string", length=255, nullable=true) |
||
226 | */ |
||
227 | protected $keyword; |
||
228 | |||
229 | /** |
||
230 | * @var string |
||
231 | * |
||
232 | * @ORM\ManyToOne(targetEntity="Victoire\Bundle\CoreBundle\Entity\Link", inversedBy="referers", cascade={"persist"}) |
||
233 | * @ORM\JoinColumn(name="redirect_to", referencedColumnName="id", onDelete="SET NULL") |
||
234 | */ |
||
235 | protected $redirectTo; |
||
236 | |||
237 | /** |
||
238 | * Get id. |
||
239 | * |
||
240 | * @return int |
||
241 | */ |
||
242 | public function getId() |
||
246 | |||
247 | /** |
||
248 | * Set redirectTo. |
||
249 | * |
||
250 | * @param View $redirectTo |
||
251 | * |
||
252 | * @return PageSeo |
||
253 | */ |
||
254 | public function setRedirectTo(Link $redirectTo) |
||
260 | |||
261 | /** |
||
262 | * Get redirectTo. |
||
263 | * |
||
264 | * @return string |
||
265 | */ |
||
266 | public function getRedirectTo() |
||
270 | |||
271 | /** |
||
272 | * Set metaTitle. |
||
273 | * |
||
274 | * @param string $metaTitle |
||
275 | * |
||
276 | * @return PageSeo |
||
277 | */ |
||
278 | public function setMetaTitle($metaTitle) |
||
284 | |||
285 | /** |
||
286 | * Get metaTitle. |
||
287 | * |
||
288 | * @return string |
||
289 | */ |
||
290 | public function getMetaTitle() |
||
294 | |||
295 | /** |
||
296 | * Set metaDescription. |
||
297 | * |
||
298 | * @param string $metaDescription |
||
299 | * |
||
300 | * @return PageSeo |
||
301 | */ |
||
302 | public function setMetaDescription($metaDescription) |
||
308 | |||
309 | /** |
||
310 | * Get metaDescription. |
||
311 | * |
||
312 | * @return string |
||
313 | */ |
||
314 | public function getMetaDescription() |
||
318 | |||
319 | /** |
||
320 | * Set relAuthor. |
||
321 | * |
||
322 | * @param string $relAuthor |
||
323 | * |
||
324 | * @return PageSeo |
||
325 | */ |
||
326 | public function setRelAuthor($relAuthor) |
||
332 | |||
333 | /** |
||
334 | * Get relAuthor. |
||
335 | * |
||
336 | * @return string |
||
337 | */ |
||
338 | public function getRelAuthor() |
||
342 | |||
343 | /** |
||
344 | * Set relPublisher. |
||
345 | * |
||
346 | * @param string $relPublisher |
||
347 | * |
||
348 | * @return PageSeo |
||
349 | */ |
||
350 | public function setRelPublisher($relPublisher) |
||
356 | |||
357 | /** |
||
358 | * Get relPublisher. |
||
359 | * |
||
360 | * @return string |
||
361 | */ |
||
362 | public function getRelPublisher() |
||
366 | |||
367 | /** |
||
368 | * Set ogTitle. |
||
369 | * |
||
370 | * @param string $ogTitle |
||
371 | * |
||
372 | * @return PageSeo |
||
373 | */ |
||
374 | public function setOgTitle($ogTitle) |
||
380 | |||
381 | /** |
||
382 | * Get ogTitle. |
||
383 | * |
||
384 | * @return string |
||
385 | */ |
||
386 | public function getOgTitle() |
||
390 | |||
391 | /** |
||
392 | * Set ogType. |
||
393 | * |
||
394 | * @param string $ogType |
||
395 | * |
||
396 | * @return PageSeo |
||
397 | */ |
||
398 | public function setOgType($ogType) |
||
404 | |||
405 | /** |
||
406 | * Get ogType. |
||
407 | * |
||
408 | * @return string |
||
409 | */ |
||
410 | public function getOgType() |
||
414 | |||
415 | /** |
||
416 | * Set ogImage. |
||
417 | * |
||
418 | * @param Image $ogImage |
||
419 | * |
||
420 | * @return PageSeo |
||
421 | */ |
||
422 | public function setOgImage($ogImage) |
||
428 | |||
429 | /** |
||
430 | * Get ogImage. |
||
431 | * |
||
432 | * @return string |
||
433 | */ |
||
434 | public function getOgImage() |
||
438 | |||
439 | /** |
||
440 | * Set ogUrl. |
||
441 | * |
||
442 | * @param string $ogUrl |
||
443 | * |
||
444 | * @return PageSeo |
||
445 | */ |
||
446 | public function setOgUrl($ogUrl) |
||
452 | |||
453 | /** |
||
454 | * Get ogUrl. |
||
455 | * |
||
456 | * @return string |
||
457 | */ |
||
458 | public function getOgUrl() |
||
462 | |||
463 | /** |
||
464 | * Set ogDescription. |
||
465 | * |
||
466 | * @param string $ogDescription |
||
467 | * |
||
468 | * @return PageSeo |
||
469 | */ |
||
470 | public function setOgDescription($ogDescription) |
||
476 | |||
477 | /** |
||
478 | * Get ogDescription. |
||
479 | * |
||
480 | * @return string |
||
481 | */ |
||
482 | public function getOgDescription() |
||
486 | |||
487 | /** |
||
488 | * Set fbAdmins. |
||
489 | * |
||
490 | * @param string $fbAdmins |
||
491 | * |
||
492 | * @return PageSeo |
||
493 | */ |
||
494 | public function setFbAdmins($fbAdmins) |
||
500 | |||
501 | /** |
||
502 | * Get fbAdmins. |
||
503 | * |
||
504 | * @return string |
||
505 | */ |
||
506 | public function getFbAdmins() |
||
510 | |||
511 | /** |
||
512 | * Set twitterCard. |
||
513 | * |
||
514 | * @param string $twitterCard |
||
515 | * |
||
516 | * @return PageSeo |
||
517 | */ |
||
518 | public function setTwitterCard($twitterCard) |
||
524 | |||
525 | /** |
||
526 | * Get twitterCard. |
||
527 | * |
||
528 | * @return string |
||
529 | */ |
||
530 | public function getTwitterCard() |
||
534 | |||
535 | /** |
||
536 | * Set twitterUrl. |
||
537 | * |
||
538 | * @param string $twitterUrl |
||
539 | * |
||
540 | * @return PageSeo |
||
541 | */ |
||
542 | public function setTwitterUrl($twitterUrl) |
||
548 | |||
549 | /** |
||
550 | * Get twitterUrl. |
||
551 | * |
||
552 | * @return string |
||
553 | */ |
||
554 | public function getTwitterUrl() |
||
558 | |||
559 | /** |
||
560 | * Set twitterCreator. |
||
561 | * |
||
562 | * @param string $twitterCreator |
||
563 | * |
||
564 | * @return PageSeo |
||
565 | */ |
||
566 | public function setTwitterCreator($twitterCreator) |
||
572 | |||
573 | /** |
||
574 | * Get twitterCreator. |
||
575 | * |
||
576 | * @return string |
||
577 | */ |
||
578 | public function getTwitterCreator() |
||
582 | |||
583 | /** |
||
584 | * Set twitterTitle. |
||
585 | * |
||
586 | * @param string $twitterTitle |
||
587 | * |
||
588 | * @return PageSeo |
||
589 | */ |
||
590 | public function setTwitterTitle($twitterTitle) |
||
596 | |||
597 | /** |
||
598 | * Get twitterTitle. |
||
599 | * |
||
600 | * @return string |
||
601 | */ |
||
602 | public function getTwitterTitle() |
||
606 | |||
607 | /** |
||
608 | * Set twitterDescription. |
||
609 | * |
||
610 | * @param string $twitterDescription |
||
611 | * |
||
612 | * @return PageSeo |
||
613 | */ |
||
614 | public function setTwitterDescription($twitterDescription) |
||
620 | |||
621 | /** |
||
622 | * Get twitterDescription. |
||
623 | * |
||
624 | * @return string |
||
625 | */ |
||
626 | public function getTwitterDescription() |
||
630 | |||
631 | /** |
||
632 | * Set twitterImage. |
||
633 | * |
||
634 | * @param Image $twitterImage |
||
635 | * |
||
636 | * @return PageSeo |
||
637 | */ |
||
638 | public function setTwitterImage($twitterImage) |
||
644 | |||
645 | /** |
||
646 | * Get twitterImage. |
||
647 | * |
||
648 | * @return string |
||
649 | */ |
||
650 | public function getTwitterImage() |
||
654 | |||
655 | /** |
||
656 | * Set schemaPageType. |
||
657 | * |
||
658 | * @param string $schemaPageType |
||
659 | * |
||
660 | * @return PageSeo |
||
661 | */ |
||
662 | public function setSchemaPageType($schemaPageType) |
||
668 | |||
669 | /** |
||
670 | * Get schemaPageType. |
||
671 | * |
||
672 | * @return string |
||
673 | */ |
||
674 | public function getSchemaPageType() |
||
678 | |||
679 | /** |
||
680 | * Set schemaName. |
||
681 | * |
||
682 | * @param string $schemaName |
||
683 | * |
||
684 | * @return PageSeo |
||
685 | */ |
||
686 | public function setSchemaName($schemaName) |
||
692 | |||
693 | /** |
||
694 | * Get schemaName. |
||
695 | * |
||
696 | * @return string |
||
697 | */ |
||
698 | public function getSchemaName() |
||
702 | |||
703 | /** |
||
704 | * Set schemaDescription. |
||
705 | * |
||
706 | * @param string $schemaDescription |
||
707 | * |
||
708 | * @return PageSeo |
||
709 | */ |
||
710 | public function setSchemaDescription($schemaDescription) |
||
716 | |||
717 | /** |
||
718 | * Get schemaDescription. |
||
719 | * |
||
720 | * @return string |
||
721 | */ |
||
722 | public function getSchemaDescription() |
||
726 | |||
727 | /** |
||
728 | * Set schemaImage. |
||
729 | * |
||
730 | * @param Image $schemaImage |
||
731 | * |
||
732 | * @return PageSeo |
||
733 | */ |
||
734 | public function setSchemaImage($schemaImage) |
||
740 | |||
741 | /** |
||
742 | * Get schemaImage. |
||
743 | * |
||
744 | * @return string |
||
745 | */ |
||
746 | public function getSchemaImage() |
||
750 | |||
751 | /** |
||
752 | * Set metaRobotsIndex. |
||
753 | * |
||
754 | * @param string $metaRobotsIndex |
||
755 | * |
||
756 | * @return PageSeo |
||
757 | */ |
||
758 | public function setMetaRobotsIndex($metaRobotsIndex) |
||
764 | |||
765 | /** |
||
766 | * Get metaRobotsIndex. |
||
767 | * |
||
768 | * @return string |
||
769 | */ |
||
770 | public function getMetaRobotsIndex() |
||
774 | |||
775 | /** |
||
776 | * Set metaRobotsFollow. |
||
777 | * |
||
778 | * @param string $metaRobotsFollow |
||
779 | * |
||
780 | * @return PageSeo |
||
781 | */ |
||
782 | public function setMetaRobotsFollow($metaRobotsFollow) |
||
788 | |||
789 | /** |
||
790 | * Get metaRobotsFollow. |
||
791 | * |
||
792 | * @return string |
||
793 | */ |
||
794 | public function getMetaRobotsFollow() |
||
798 | |||
799 | /** |
||
800 | * Set metaRobotsAdvanced. |
||
801 | * |
||
802 | * @param string $metaRobotsAdvanced |
||
803 | * |
||
804 | * @return PageSeo |
||
805 | */ |
||
806 | public function setMetaRobotsAdvanced($metaRobotsAdvanced) |
||
812 | |||
813 | /** |
||
814 | * Get metaRobotsAdvanced. |
||
815 | * |
||
816 | * @return string |
||
817 | */ |
||
818 | public function getMetaRobotsAdvanced() |
||
822 | |||
823 | /** |
||
824 | * Set sitemapIndexed. |
||
825 | * |
||
826 | * @param bool $sitemapIndexed |
||
827 | * |
||
828 | * @return PageSeo |
||
829 | */ |
||
830 | public function setSitemapIndexed($sitemapIndexed) |
||
836 | |||
837 | /** |
||
838 | * Get sitemapIndexed. |
||
839 | * |
||
840 | * @return bool |
||
841 | */ |
||
842 | public function isSitemapIndexed() |
||
846 | |||
847 | /** |
||
848 | * Set sitemapPriority. |
||
849 | * |
||
850 | * @param float $sitemapPriority |
||
851 | * |
||
852 | * @return PageSeo |
||
853 | */ |
||
854 | public function setSitemapPriority($sitemapPriority) |
||
860 | |||
861 | /** |
||
862 | * Get sitemapPriority. |
||
863 | * |
||
864 | * @return float |
||
865 | */ |
||
866 | public function getSitemapPriority() |
||
870 | |||
871 | /** |
||
872 | * Set sitemapChangeFreq. |
||
873 | * |
||
874 | * @param float $sitemapChangeFreq |
||
875 | * |
||
876 | * @return PageSeo |
||
877 | */ |
||
878 | public function setSitemapChangeFreq($sitemapChangeFreq) |
||
884 | |||
885 | /** |
||
886 | * Get sitemapChangeFreq. |
||
887 | * |
||
888 | * @return float |
||
889 | */ |
||
890 | public function getSitemapChangeFreq() |
||
894 | |||
895 | /** |
||
896 | * Set relCanonical. |
||
897 | * |
||
898 | * @param string $relCanonical |
||
899 | * |
||
900 | * @return PageSeo |
||
901 | */ |
||
902 | public function setRelCanonical($relCanonical) |
||
908 | |||
909 | /** |
||
910 | * Get relCanonical. |
||
911 | * |
||
912 | * @return string |
||
913 | */ |
||
914 | public function getRelCanonical() |
||
918 | |||
919 | /** |
||
920 | * Set keyword. |
||
921 | * |
||
922 | * @param string $keyword |
||
923 | * |
||
924 | * @return PageSeo |
||
925 | */ |
||
926 | public function setKeyword($keyword) |
||
932 | |||
933 | /** |
||
934 | * Get keyword. |
||
935 | * |
||
936 | * @return string |
||
937 | */ |
||
938 | public function getKeyword() |
||
942 | } |
||
943 |
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..