Complex classes like PageSeo 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 PageSeo, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class PageSeo |
||
16 | { |
||
17 | use \Gedmo\Timestampable\Traits\TimestampableEntity; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | * |
||
22 | * @ORM\Column(name="id", type="integer") |
||
23 | * @ORM\Id |
||
24 | * @ORM\GeneratedValue(strategy="AUTO") |
||
25 | */ |
||
26 | protected $id; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | * |
||
31 | * @ORM\Column(name="meta_title", type="string", nullable=true) |
||
32 | * @Assert\Length(max = 60) |
||
33 | */ |
||
34 | protected $metaTitle; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | * |
||
39 | * @ORM\Column(name="meta_description", type="string", length=255, nullable=true) |
||
40 | * @Assert\Length(max = 155) |
||
41 | */ |
||
42 | protected $metaDescription; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | * |
||
47 | * @ORM\Column(name="rel_author", type="string", length=255, nullable=true) |
||
48 | */ |
||
49 | protected $relAuthor; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | * |
||
54 | * @ORM\Column(name="rel_publisher", type="string", length=255, nullable=true) |
||
55 | */ |
||
56 | protected $relPublisher; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | * |
||
61 | * @ORM\Column(name="ogTitle", type="string", length=255, nullable=true) |
||
62 | */ |
||
63 | protected $ogTitle; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | * |
||
68 | * @ORM\Column(name="ogType", type="string", length=255, nullable=true) |
||
69 | */ |
||
70 | protected $ogType; |
||
71 | |||
72 | /** |
||
73 | * @var string |
||
74 | * |
||
75 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
76 | * @ORM\JoinColumn(name="ogImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
77 | */ |
||
78 | protected $ogImage; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | * |
||
83 | * @ORM\Column(name="ogUrl", type="string", length=255, nullable=true) |
||
84 | */ |
||
85 | protected $ogUrl; |
||
86 | |||
87 | /** |
||
88 | * @var text |
||
89 | * |
||
90 | * @ORM\Column(name="ogDescription", type="text", nullable=true) |
||
91 | */ |
||
92 | protected $ogDescription; |
||
93 | |||
94 | /** |
||
95 | * @var string |
||
96 | * |
||
97 | * @ORM\Column(name="fbAdmins", type="string", length=255, nullable=true) |
||
98 | */ |
||
99 | protected $fbAdmins; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | * |
||
104 | * @ORM\Column(name="twitterCard", type="string", length=255, nullable=true) |
||
105 | */ |
||
106 | protected $twitterCard = 'summary'; |
||
107 | |||
108 | /** |
||
109 | * @var string |
||
110 | * |
||
111 | * @ORM\Column(name="twitterUrl", type="string", length=255, nullable=true) |
||
112 | * @Assert\Length(max = 15) |
||
113 | */ |
||
114 | protected $twitterUrl; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | * |
||
119 | * @ORM\Column(name="twitterCreator", type="string", length=255, nullable=true) |
||
120 | * @Assert\Length(max = 15) |
||
121 | */ |
||
122 | protected $twitterCreator; |
||
123 | |||
124 | /** |
||
125 | * @var string |
||
126 | * |
||
127 | * @ORM\Column(name="twitterTitle", type="string", length=255, nullable=true) |
||
128 | * @Assert\Length(max = 70) |
||
129 | */ |
||
130 | protected $twitterTitle; |
||
131 | |||
132 | /** |
||
133 | * @var string |
||
134 | * |
||
135 | * @ORM\Column(name="twitterDescription", type="string", length=255, nullable=true) |
||
136 | * @Assert\Length(max = 200) |
||
137 | */ |
||
138 | protected $twitterDescription; |
||
139 | |||
140 | /** |
||
141 | * @var string |
||
142 | * |
||
143 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
144 | * @ORM\JoinColumn(name="twitterImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
145 | */ |
||
146 | protected $twitterImage; |
||
147 | |||
148 | /** |
||
149 | * @var string |
||
150 | * |
||
151 | * @ORM\Column(name="schemaPageType", type="string", length=255, nullable=true) |
||
152 | */ |
||
153 | protected $schemaPageType; |
||
154 | |||
155 | /** |
||
156 | * @var string |
||
157 | * |
||
158 | * @ORM\Column(name="schemaName", type="string", length=255, nullable=true) |
||
159 | */ |
||
160 | protected $schemaName; |
||
161 | |||
162 | /** |
||
163 | * @var string |
||
164 | * |
||
165 | * @ORM\Column(name="schemaDescription", type="string", length=255, nullable=true) |
||
166 | */ |
||
167 | protected $schemaDescription; |
||
168 | |||
169 | /** |
||
170 | * @var string |
||
171 | * |
||
172 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
173 | * @ORM\JoinColumn(name="schemaImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
174 | */ |
||
175 | protected $schemaImage; |
||
176 | |||
177 | /** |
||
178 | * @var string |
||
179 | * |
||
180 | * @ORM\Column(name="meta_robots_index", type="string", length=255, nullable=true) |
||
181 | */ |
||
182 | protected $metaRobotsIndex; |
||
183 | |||
184 | /** |
||
185 | * @var string |
||
186 | * |
||
187 | * @ORM\Column(name="meta_robots_follow", type="string", length=255, nullable=true) |
||
188 | */ |
||
189 | protected $metaRobotsFollow; |
||
190 | |||
191 | /** |
||
192 | * @var string |
||
193 | * |
||
194 | * @ORM\Column(name="meta_robots_advanced", type="string", length=255, nullable=true) |
||
195 | */ |
||
196 | protected $metaRobotsAdvanced; |
||
197 | |||
198 | /** |
||
199 | * @var bool |
||
200 | * |
||
201 | * @ORM\Column(name="sitemap_indexed", type="boolean", nullable=true, options={"default" = true}) |
||
202 | */ |
||
203 | protected $sitemapIndexed = true; |
||
204 | |||
205 | /** |
||
206 | * @var float |
||
207 | * |
||
208 | * @ORM\Column(name="sitemap_priority", type="float", nullable=true, options={"default" = "0.8"}) |
||
209 | */ |
||
210 | protected $sitemapPriority = 0.8; |
||
211 | |||
212 | /** |
||
213 | * @var string |
||
214 | * |
||
215 | * @ORM\Column(name="sitemap_changeFreq", type="string", length=20, nullable=true, options={"default" = "monthly"}) |
||
216 | */ |
||
217 | protected $sitemapChangeFreq = 'monthly'; |
||
218 | |||
219 | /** |
||
220 | * @var string |
||
221 | * |
||
222 | * @ORM\Column(name="rel_canonical", type="string", length=255, nullable=true) |
||
223 | */ |
||
224 | protected $relCanonical; |
||
225 | |||
226 | /** |
||
227 | * @var string |
||
228 | * |
||
229 | * @ORM\Column(name="keyword", type="string", length=255, nullable=true) |
||
230 | */ |
||
231 | protected $keyword; |
||
232 | |||
233 | /** |
||
234 | * @var string |
||
235 | * |
||
236 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\PageBundle\Entity\Page", inversedBy="referers", cascade={"persist"}) |
||
237 | * @ORM\JoinColumn(name="redirect_to", referencedColumnName="id", onDelete="SET NULL") |
||
238 | */ |
||
239 | protected $redirectTo; |
||
240 | |||
241 | /** |
||
242 | * contructor. |
||
243 | **/ |
||
244 | public function __construct() |
||
249 | |||
250 | /** |
||
251 | * Get id. |
||
252 | * |
||
253 | * @return int |
||
254 | */ |
||
255 | public function getId() |
||
259 | |||
260 | /** |
||
261 | * Set redirectTo. |
||
262 | * |
||
263 | * @param View $redirectTo |
||
264 | * |
||
265 | * @return PageSeo |
||
266 | */ |
||
267 | public function setRedirectTo(View $redirectTo) |
||
273 | |||
274 | /** |
||
275 | * Get redirectTo. |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | public function getRedirectTo() |
||
283 | |||
284 | /** |
||
285 | * Set metaTitle. |
||
286 | * |
||
287 | * @param string $metaTitle |
||
288 | * |
||
289 | * @return PageSeo |
||
290 | */ |
||
291 | public function setMetaTitle($metaTitle) |
||
297 | |||
298 | /** |
||
299 | * Get metaTitle. |
||
300 | * |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getMetaTitle() |
||
307 | |||
308 | /** |
||
309 | * Set metaDescription. |
||
310 | * |
||
311 | * @param string $metaDescription |
||
312 | * |
||
313 | * @return PageSeo |
||
314 | */ |
||
315 | public function setMetaDescription($metaDescription) |
||
321 | |||
322 | /** |
||
323 | * Get metaDescription. |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | public function getMetaDescription() |
||
331 | |||
332 | /** |
||
333 | * Set relAuthor. |
||
334 | * |
||
335 | * @param string $relAuthor |
||
336 | * |
||
337 | * @return PageSeo |
||
338 | */ |
||
339 | public function setRelAuthor($relAuthor) |
||
345 | |||
346 | /** |
||
347 | * Get relAuthor. |
||
348 | * |
||
349 | * @return string |
||
350 | */ |
||
351 | public function getRelAuthor() |
||
355 | |||
356 | /** |
||
357 | * Set relPublisher. |
||
358 | * |
||
359 | * @param string $relPublisher |
||
360 | * |
||
361 | * @return PageSeo |
||
362 | */ |
||
363 | public function setRelPublisher($relPublisher) |
||
369 | |||
370 | /** |
||
371 | * Get relPublisher. |
||
372 | * |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getRelPublisher() |
||
379 | |||
380 | /** |
||
381 | * Set ogTitle. |
||
382 | * |
||
383 | * @param string $ogTitle |
||
384 | * |
||
385 | * @return PageSeo |
||
386 | */ |
||
387 | public function setOgTitle($ogTitle) |
||
393 | |||
394 | /** |
||
395 | * Get ogTitle. |
||
396 | * |
||
397 | * @return string |
||
398 | */ |
||
399 | public function getOgTitle() |
||
403 | |||
404 | /** |
||
405 | * Set ogType. |
||
406 | * |
||
407 | * @param string $ogType |
||
408 | * |
||
409 | * @return PageSeo |
||
410 | */ |
||
411 | public function setOgType($ogType) |
||
417 | |||
418 | /** |
||
419 | * Get ogType. |
||
420 | * |
||
421 | * @return string |
||
422 | */ |
||
423 | public function getOgType() |
||
427 | |||
428 | /** |
||
429 | * Set ogImage. |
||
430 | * |
||
431 | * @param Image $ogImage |
||
432 | * |
||
433 | * @return PageSeo |
||
434 | */ |
||
435 | public function setOgImage($ogImage) |
||
441 | |||
442 | /** |
||
443 | * Get ogImage. |
||
444 | * |
||
445 | * @return string |
||
446 | */ |
||
447 | public function getOgImage() |
||
451 | |||
452 | /** |
||
453 | * Set ogUrl. |
||
454 | * |
||
455 | * @param string $ogUrl |
||
456 | * |
||
457 | * @return PageSeo |
||
458 | */ |
||
459 | public function setOgUrl($ogUrl) |
||
465 | |||
466 | /** |
||
467 | * Get ogUrl. |
||
468 | * |
||
469 | * @return string |
||
470 | */ |
||
471 | public function getOgUrl() |
||
475 | |||
476 | /** |
||
477 | * Set ogDescription. |
||
478 | * |
||
479 | * @param string $ogDescription |
||
480 | * |
||
481 | * @return PageSeo |
||
482 | */ |
||
483 | public function setOgDescription($ogDescription) |
||
489 | |||
490 | /** |
||
491 | * Get ogDescription. |
||
492 | * |
||
493 | * @return string |
||
494 | */ |
||
495 | public function getOgDescription() |
||
499 | |||
500 | /** |
||
501 | * Set fbAdmins. |
||
502 | * |
||
503 | * @param string $fbAdmins |
||
504 | * |
||
505 | * @return PageSeo |
||
506 | */ |
||
507 | public function setFbAdmins($fbAdmins) |
||
513 | |||
514 | /** |
||
515 | * Get fbAdmins. |
||
516 | * |
||
517 | * @return string |
||
518 | */ |
||
519 | public function getFbAdmins() |
||
523 | |||
524 | /** |
||
525 | * Set twitterCard. |
||
526 | * |
||
527 | * @param string $twitterCard |
||
528 | * |
||
529 | * @return PageSeo |
||
530 | */ |
||
531 | public function setTwitterCard($twitterCard) |
||
537 | |||
538 | /** |
||
539 | * Get twitterCard. |
||
540 | * |
||
541 | * @return string |
||
542 | */ |
||
543 | public function getTwitterCard() |
||
547 | |||
548 | /** |
||
549 | * Set twitterUrl. |
||
550 | * |
||
551 | * @param string $twitterUrl |
||
552 | * |
||
553 | * @return PageSeo |
||
554 | */ |
||
555 | public function setTwitterUrl($twitterUrl) |
||
561 | |||
562 | /** |
||
563 | * Get twitterUrl. |
||
564 | * |
||
565 | * @return string |
||
566 | */ |
||
567 | public function getTwitterUrl() |
||
571 | |||
572 | /** |
||
573 | * Set twitterCreator. |
||
574 | * |
||
575 | * @param string $twitterCreator |
||
576 | * |
||
577 | * @return PageSeo |
||
578 | */ |
||
579 | public function setTwitterCreator($twitterCreator) |
||
585 | |||
586 | /** |
||
587 | * Get twitterCreator. |
||
588 | * |
||
589 | * @return string |
||
590 | */ |
||
591 | public function getTwitterCreator() |
||
595 | |||
596 | /** |
||
597 | * Set twitterTitle. |
||
598 | * |
||
599 | * @param string $twitterTitle |
||
600 | * |
||
601 | * @return PageSeo |
||
602 | */ |
||
603 | public function setTwitterTitle($twitterTitle) |
||
609 | |||
610 | /** |
||
611 | * Get twitterTitle. |
||
612 | * |
||
613 | * @return string |
||
614 | */ |
||
615 | public function getTwitterTitle() |
||
619 | |||
620 | /** |
||
621 | * Set twitterDescription. |
||
622 | * |
||
623 | * @param string $twitterDescription |
||
624 | * |
||
625 | * @return PageSeo |
||
626 | */ |
||
627 | public function setTwitterDescription($twitterDescription) |
||
633 | |||
634 | /** |
||
635 | * Get twitterDescription. |
||
636 | * |
||
637 | * @return string |
||
638 | */ |
||
639 | public function getTwitterDescription() |
||
643 | |||
644 | /** |
||
645 | * Set twitterImage. |
||
646 | * |
||
647 | * @param Image $twitterImage |
||
648 | * |
||
649 | * @return PageSeo |
||
650 | */ |
||
651 | public function setTwitterImage($twitterImage) |
||
657 | |||
658 | /** |
||
659 | * Get twitterImage. |
||
660 | * |
||
661 | * @return string |
||
662 | */ |
||
663 | public function getTwitterImage() |
||
667 | |||
668 | /** |
||
669 | * Set schemaPageType. |
||
670 | * |
||
671 | * @param string $schemaPageType |
||
672 | * |
||
673 | * @return PageSeo |
||
674 | */ |
||
675 | public function setSchemaPageType($schemaPageType) |
||
681 | |||
682 | /** |
||
683 | * Get schemaPageType. |
||
684 | * |
||
685 | * @return string |
||
686 | */ |
||
687 | public function getSchemaPageType() |
||
691 | |||
692 | /** |
||
693 | * Set schemaName. |
||
694 | * |
||
695 | * @param string $schemaName |
||
696 | * |
||
697 | * @return PageSeo |
||
698 | */ |
||
699 | public function setSchemaName($schemaName) |
||
705 | |||
706 | /** |
||
707 | * Get schemaName. |
||
708 | * |
||
709 | * @return string |
||
710 | */ |
||
711 | public function getSchemaName() |
||
715 | |||
716 | /** |
||
717 | * Set schemaDescription. |
||
718 | * |
||
719 | * @param string $schemaDescription |
||
720 | * |
||
721 | * @return PageSeo |
||
722 | */ |
||
723 | public function setSchemaDescription($schemaDescription) |
||
729 | |||
730 | /** |
||
731 | * Get schemaDescription. |
||
732 | * |
||
733 | * @return string |
||
734 | */ |
||
735 | public function getSchemaDescription() |
||
739 | |||
740 | /** |
||
741 | * Set schemaImage. |
||
742 | * |
||
743 | * @param Image $schemaImage |
||
744 | * |
||
745 | * @return PageSeo |
||
746 | */ |
||
747 | public function setSchemaImage($schemaImage) |
||
753 | |||
754 | /** |
||
755 | * Get schemaImage. |
||
756 | * |
||
757 | * @return string |
||
758 | */ |
||
759 | public function getSchemaImage() |
||
763 | |||
764 | /** |
||
765 | * Set metaRobotsIndex. |
||
766 | * |
||
767 | * @param string $metaRobotsIndex |
||
768 | * |
||
769 | * @return PageSeo |
||
770 | */ |
||
771 | public function setMetaRobotsIndex($metaRobotsIndex) |
||
777 | |||
778 | /** |
||
779 | * Get metaRobotsIndex. |
||
780 | * |
||
781 | * @return string |
||
782 | */ |
||
783 | public function getMetaRobotsIndex() |
||
787 | |||
788 | /** |
||
789 | * Set metaRobotsFollow. |
||
790 | * |
||
791 | * @param string $metaRobotsFollow |
||
792 | * |
||
793 | * @return PageSeo |
||
794 | */ |
||
795 | public function setMetaRobotsFollow($metaRobotsFollow) |
||
801 | |||
802 | /** |
||
803 | * Get metaRobotsFollow. |
||
804 | * |
||
805 | * @return string |
||
806 | */ |
||
807 | public function getMetaRobotsFollow() |
||
811 | |||
812 | /** |
||
813 | * Set metaRobotsAdvanced. |
||
814 | * |
||
815 | * @param string $metaRobotsAdvanced |
||
816 | * |
||
817 | * @return PageSeo |
||
818 | */ |
||
819 | public function setMetaRobotsAdvanced($metaRobotsAdvanced) |
||
825 | |||
826 | /** |
||
827 | * Get metaRobotsAdvanced. |
||
828 | * |
||
829 | * @return string |
||
830 | */ |
||
831 | public function getMetaRobotsAdvanced() |
||
835 | |||
836 | /** |
||
837 | * Set sitemapIndexed. |
||
838 | * |
||
839 | * @param bool $sitemapIndexed |
||
840 | * |
||
841 | * @return PageSeo |
||
842 | */ |
||
843 | public function setSitemapIndexed($sitemapIndexed) |
||
849 | |||
850 | /** |
||
851 | * Get sitemapIndexed. |
||
852 | * |
||
853 | * @return bool |
||
854 | */ |
||
855 | public function isSitemapIndexed() |
||
859 | |||
860 | /** |
||
861 | * Set sitemapPriority. |
||
862 | * |
||
863 | * @param float $sitemapPriority |
||
864 | * |
||
865 | * @return PageSeo |
||
866 | */ |
||
867 | public function setSitemapPriority($sitemapPriority) |
||
873 | |||
874 | /** |
||
875 | * Get sitemapPriority. |
||
876 | * |
||
877 | * @return float |
||
878 | */ |
||
879 | public function getSitemapPriority() |
||
883 | |||
884 | /** |
||
885 | * Set sitemapChangeFreq. |
||
886 | * |
||
887 | * @param float $sitemapChangeFreq |
||
888 | * |
||
889 | * @return PageSeo |
||
890 | */ |
||
891 | public function setSitemapChangeFreq($sitemapChangeFreq) |
||
897 | |||
898 | /** |
||
899 | * Get sitemapChangeFreq. |
||
900 | * |
||
901 | * @return float |
||
902 | */ |
||
903 | public function getSitemapChangeFreq() |
||
907 | |||
908 | /** |
||
909 | * Set relCanonical. |
||
910 | * |
||
911 | * @param string $relCanonical |
||
912 | * |
||
913 | * @return PageSeo |
||
914 | */ |
||
915 | public function setRelCanonical($relCanonical) |
||
921 | |||
922 | /** |
||
923 | * Get relCanonical. |
||
924 | * |
||
925 | * @return string |
||
926 | */ |
||
927 | public function getRelCanonical() |
||
931 | |||
932 | /** |
||
933 | * Set keyword. |
||
934 | * |
||
935 | * @param string $keyword |
||
936 | * |
||
937 | * @return PageSeo |
||
938 | */ |
||
939 | public function setKeyword($keyword) |
||
945 | |||
946 | /** |
||
947 | * Get keyword. |
||
948 | * |
||
949 | * @return string |
||
950 | */ |
||
951 | public function getKeyword() |
||
955 | } |
||
956 |
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..