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 |
||
16 | class PageSeo |
||
17 | { |
||
18 | use \Gedmo\Timestampable\Traits\TimestampableEntity; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | * |
||
23 | * @ORM\Column(name="id", type="integer") |
||
24 | * @ORM\Id |
||
25 | * @ORM\GeneratedValue(strategy="AUTO") |
||
26 | */ |
||
27 | protected $id; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | * |
||
32 | * @ORM\Column(name="meta_title", type="string", nullable=true) |
||
33 | * @Assert\Length(max = 60) |
||
34 | * @Gedmo\Translatable |
||
35 | */ |
||
36 | protected $metaTitle; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * |
||
41 | * @ORM\Column(name="meta_description", type="string", length=255, nullable=true) |
||
42 | * @Assert\Length(max = 155) |
||
43 | * @Gedmo\Translatable |
||
44 | */ |
||
45 | protected $metaDescription; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | * |
||
50 | * @ORM\Column(name="rel_author", type="string", length=255, nullable=true) |
||
51 | * @Gedmo\Translatable |
||
52 | */ |
||
53 | protected $relAuthor; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | * |
||
58 | * @ORM\Column(name="rel_publisher", type="string", length=255, nullable=true) |
||
59 | * @Gedmo\Translatable |
||
60 | */ |
||
61 | protected $relPublisher; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | * |
||
66 | * @ORM\Column(name="ogTitle", type="string", length=255, nullable=true) |
||
67 | * @Gedmo\Translatable |
||
68 | */ |
||
69 | protected $ogTitle; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | * |
||
74 | * @ORM\Column(name="ogType", type="string", length=255, nullable=true) |
||
75 | * @Gedmo\Translatable |
||
76 | */ |
||
77 | protected $ogType; |
||
78 | |||
79 | /** |
||
80 | * @var string |
||
81 | * |
||
82 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
83 | * @ORM\JoinColumn(name="ogImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
84 | */ |
||
85 | protected $ogImage; |
||
86 | |||
87 | /** |
||
88 | * @var string |
||
89 | * |
||
90 | * @ORM\Column(name="ogUrl", type="string", length=255, nullable=true) |
||
91 | * @Gedmo\Translatable |
||
92 | */ |
||
93 | protected $ogUrl; |
||
94 | |||
95 | /** |
||
96 | * @var text |
||
97 | * |
||
98 | * @ORM\Column(name="ogDescription", type="text", nullable=true) |
||
99 | * @Gedmo\Translatable |
||
100 | */ |
||
101 | protected $ogDescription; |
||
102 | |||
103 | /** |
||
104 | * @var string |
||
105 | * |
||
106 | * @ORM\Column(name="fbAdmins", type="string", length=255, nullable=true) |
||
107 | * @Gedmo\Translatable |
||
108 | */ |
||
109 | protected $fbAdmins; |
||
110 | |||
111 | /** |
||
112 | * @var string |
||
113 | * |
||
114 | * @ORM\Column(name="twitterCard", type="string", length=255, nullable=true) |
||
115 | * @Gedmo\Translatable |
||
116 | */ |
||
117 | protected $twitterCard = 'summary'; |
||
118 | |||
119 | /** |
||
120 | * @var string |
||
121 | * |
||
122 | * @ORM\Column(name="twitterUrl", type="string", length=255, nullable=true) |
||
123 | * @Gedmo\Translatable |
||
124 | * @Assert\Length(max = 15) |
||
125 | */ |
||
126 | protected $twitterUrl; |
||
127 | |||
128 | /** |
||
129 | * @var string |
||
130 | * |
||
131 | * @ORM\Column(name="twitterCreator", type="string", length=255, nullable=true) |
||
132 | * @Gedmo\Translatable |
||
133 | * @Assert\Length(max = 15) |
||
134 | */ |
||
135 | protected $twitterCreator; |
||
136 | |||
137 | /** |
||
138 | * @var string |
||
139 | * |
||
140 | * @ORM\Column(name="twitterTitle", type="string", length=255, nullable=true) |
||
141 | * @Gedmo\Translatable |
||
142 | * @Assert\Length(max = 70) |
||
143 | */ |
||
144 | protected $twitterTitle; |
||
145 | |||
146 | /** |
||
147 | * @var string |
||
148 | * |
||
149 | * @ORM\Column(name="twitterDescription", type="string", length=255, nullable=true) |
||
150 | * @Gedmo\Translatable |
||
151 | * @Assert\Length(max = 200) |
||
152 | */ |
||
153 | protected $twitterDescription; |
||
154 | |||
155 | /** |
||
156 | * @var string |
||
157 | * |
||
158 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
159 | * @ORM\JoinColumn(name="twitterImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
160 | */ |
||
161 | protected $twitterImage; |
||
162 | |||
163 | /** |
||
164 | * @var string |
||
165 | * |
||
166 | * @ORM\Column(name="schemaPageType", type="string", length=255, nullable=true) |
||
167 | * @Gedmo\Translatable |
||
168 | */ |
||
169 | protected $schemaPageType; |
||
170 | |||
171 | /** |
||
172 | * @var string |
||
173 | * |
||
174 | * @ORM\Column(name="schemaName", type="string", length=255, nullable=true) |
||
175 | * @Gedmo\Translatable |
||
176 | */ |
||
177 | protected $schemaName; |
||
178 | |||
179 | /** |
||
180 | * @var string |
||
181 | * |
||
182 | * @ORM\Column(name="schemaDescription", type="string", length=255, nullable=true) |
||
183 | * @Gedmo\Translatable |
||
184 | */ |
||
185 | protected $schemaDescription; |
||
186 | |||
187 | /** |
||
188 | * @var string |
||
189 | * |
||
190 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
||
191 | * @ORM\JoinColumn(name="schemaImage_id", referencedColumnName="id", onDelete="SET NULL") |
||
192 | */ |
||
193 | protected $schemaImage; |
||
194 | |||
195 | /** |
||
196 | * @var string |
||
197 | * |
||
198 | * @ORM\Column(name="meta_robots_index", type="string", length=255, nullable=true) |
||
199 | * @Gedmo\Translatable |
||
200 | */ |
||
201 | protected $metaRobotsIndex; |
||
202 | |||
203 | /** |
||
204 | * @var string |
||
205 | * |
||
206 | * @ORM\Column(name="meta_robots_follow", type="string", length=255, nullable=true) |
||
207 | * @Gedmo\Translatable |
||
208 | */ |
||
209 | protected $metaRobotsFollow; |
||
210 | |||
211 | /** |
||
212 | * @var string |
||
213 | * |
||
214 | * @ORM\Column(name="meta_robots_advanced", type="string", length=255, nullable=true) |
||
215 | * @Gedmo\Translatable |
||
216 | */ |
||
217 | protected $metaRobotsAdvanced; |
||
218 | |||
219 | /** |
||
220 | * @var bool |
||
221 | * |
||
222 | * @ORM\Column(name="sitemap_indexed", type="boolean", nullable=true, options={"default" = true}) |
||
223 | * @Gedmo\Translatable |
||
224 | */ |
||
225 | protected $sitemapIndexed = true; |
||
226 | |||
227 | /** |
||
228 | * @var float |
||
229 | * |
||
230 | * @ORM\Column(name="sitemap_priority", type="float", nullable=true, options={"default" = "0.8"}) |
||
231 | * @Gedmo\Translatable |
||
232 | */ |
||
233 | protected $sitemapPriority = 0.8; |
||
234 | |||
235 | /** |
||
236 | * @var string |
||
237 | * |
||
238 | * @ORM\Column(name="sitemap_changeFreq", type="string", length=20, nullable=true, options={"default" = "monthly"}) |
||
239 | * @Gedmo\Translatable |
||
240 | */ |
||
241 | protected $sitemapChangeFreq = 'monthly'; |
||
242 | |||
243 | /** |
||
244 | * @var string |
||
245 | * |
||
246 | * @ORM\Column(name="rel_canonical", type="string", length=255, nullable=true) |
||
247 | * @Gedmo\Translatable |
||
248 | */ |
||
249 | protected $relCanonical; |
||
250 | |||
251 | /** |
||
252 | * @var string |
||
253 | * |
||
254 | * @ORM\Column(name="keyword", type="string", length=255, nullable=true) |
||
255 | * @Gedmo\Translatable |
||
256 | */ |
||
257 | protected $keyword; |
||
258 | |||
259 | /** |
||
260 | * @var string |
||
261 | * |
||
262 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\PageBundle\Entity\Page", inversedBy="referers", cascade={"persist"}) |
||
263 | * @ORM\JoinColumn(name="redirect_to", referencedColumnName="id", onDelete="SET NULL") |
||
264 | */ |
||
265 | protected $redirectTo; |
||
266 | |||
267 | /** |
||
268 | * @Gedmo\Locale |
||
269 | * Used locale to override Translation listener`s locale |
||
270 | * this is not a mapped field of entity metadata, just a simple property |
||
271 | * and it is not necessary because globally locale can be set in listener |
||
272 | */ |
||
273 | protected $locale; |
||
274 | |||
275 | /** |
||
276 | * contructor. |
||
277 | **/ |
||
278 | public function __construct() |
||
283 | |||
284 | /** |
||
285 | * Get id. |
||
286 | * |
||
287 | * @return int |
||
288 | */ |
||
289 | public function getId() |
||
293 | |||
294 | /** |
||
295 | * Set redirectTo. |
||
296 | * |
||
297 | * @param View $redirectTo |
||
298 | * |
||
299 | * @return PageSeo |
||
300 | */ |
||
301 | public function setRedirectTo(View $redirectTo) |
||
307 | |||
308 | /** |
||
309 | * Get redirectTo. |
||
310 | * |
||
311 | * @return string |
||
312 | */ |
||
313 | public function getRedirectTo() |
||
317 | |||
318 | /** |
||
319 | * Set metaTitle. |
||
320 | * |
||
321 | * @param string $metaTitle |
||
322 | * |
||
323 | * @return PageSeo |
||
324 | */ |
||
325 | public function setMetaTitle($metaTitle) |
||
331 | |||
332 | /** |
||
333 | * Get metaTitle. |
||
334 | * |
||
335 | * @return string |
||
336 | */ |
||
337 | public function getMetaTitle() |
||
341 | |||
342 | /** |
||
343 | * Set metaDescription. |
||
344 | * |
||
345 | * @param string $metaDescription |
||
346 | * |
||
347 | * @return PageSeo |
||
348 | */ |
||
349 | public function setMetaDescription($metaDescription) |
||
355 | |||
356 | /** |
||
357 | * Get metaDescription. |
||
358 | * |
||
359 | * @return string |
||
360 | */ |
||
361 | public function getMetaDescription() |
||
365 | |||
366 | /** |
||
367 | * Set relAuthor. |
||
368 | * |
||
369 | * @param string $relAuthor |
||
370 | * |
||
371 | * @return PageSeo |
||
372 | */ |
||
373 | public function setRelAuthor($relAuthor) |
||
379 | |||
380 | /** |
||
381 | * Get relAuthor. |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | public function getRelAuthor() |
||
389 | |||
390 | /** |
||
391 | * Set relPublisher. |
||
392 | * |
||
393 | * @param string $relPublisher |
||
394 | * |
||
395 | * @return PageSeo |
||
396 | */ |
||
397 | public function setRelPublisher($relPublisher) |
||
403 | |||
404 | /** |
||
405 | * Get relPublisher. |
||
406 | * |
||
407 | * @return string |
||
408 | */ |
||
409 | public function getRelPublisher() |
||
413 | |||
414 | /** |
||
415 | * Set ogTitle. |
||
416 | * |
||
417 | * @param string $ogTitle |
||
418 | * |
||
419 | * @return PageSeo |
||
420 | */ |
||
421 | public function setOgTitle($ogTitle) |
||
427 | |||
428 | /** |
||
429 | * Get ogTitle. |
||
430 | * |
||
431 | * @return string |
||
432 | */ |
||
433 | public function getOgTitle() |
||
437 | |||
438 | /** |
||
439 | * Set ogType. |
||
440 | * |
||
441 | * @param string $ogType |
||
442 | * |
||
443 | * @return PageSeo |
||
444 | */ |
||
445 | public function setOgType($ogType) |
||
451 | |||
452 | /** |
||
453 | * Get ogType. |
||
454 | * |
||
455 | * @return string |
||
456 | */ |
||
457 | public function getOgType() |
||
461 | |||
462 | /** |
||
463 | * Set ogImage. |
||
464 | * |
||
465 | * @param Image $ogImage |
||
466 | * |
||
467 | * @return PageSeo |
||
468 | */ |
||
469 | public function setOgImage($ogImage) |
||
475 | |||
476 | /** |
||
477 | * Get ogImage. |
||
478 | * |
||
479 | * @return string |
||
480 | */ |
||
481 | public function getOgImage() |
||
485 | |||
486 | /** |
||
487 | * Set ogUrl. |
||
488 | * |
||
489 | * @param string $ogUrl |
||
490 | * |
||
491 | * @return PageSeo |
||
492 | */ |
||
493 | public function setOgUrl($ogUrl) |
||
499 | |||
500 | /** |
||
501 | * Get ogUrl. |
||
502 | * |
||
503 | * @return string |
||
504 | */ |
||
505 | public function getOgUrl() |
||
509 | |||
510 | /** |
||
511 | * Set ogDescription. |
||
512 | * |
||
513 | * @param string $ogDescription |
||
514 | * |
||
515 | * @return PageSeo |
||
516 | */ |
||
517 | public function setOgDescription($ogDescription) |
||
523 | |||
524 | /** |
||
525 | * Get ogDescription. |
||
526 | * |
||
527 | * @return string |
||
528 | */ |
||
529 | public function getOgDescription() |
||
533 | |||
534 | /** |
||
535 | * Set fbAdmins. |
||
536 | * |
||
537 | * @param string $fbAdmins |
||
538 | * |
||
539 | * @return PageSeo |
||
540 | */ |
||
541 | public function setFbAdmins($fbAdmins) |
||
547 | |||
548 | /** |
||
549 | * Get fbAdmins. |
||
550 | * |
||
551 | * @return string |
||
552 | */ |
||
553 | public function getFbAdmins() |
||
557 | |||
558 | /** |
||
559 | * Set twitterCard. |
||
560 | * |
||
561 | * @param string $twitterCard |
||
562 | * |
||
563 | * @return PageSeo |
||
564 | */ |
||
565 | public function setTwitterCard($twitterCard) |
||
571 | |||
572 | /** |
||
573 | * Get twitterCard. |
||
574 | * |
||
575 | * @return string |
||
576 | */ |
||
577 | public function getTwitterCard() |
||
581 | |||
582 | /** |
||
583 | * Set twitterUrl. |
||
584 | * |
||
585 | * @param string $twitterUrl |
||
586 | * |
||
587 | * @return PageSeo |
||
588 | */ |
||
589 | public function setTwitterUrl($twitterUrl) |
||
595 | |||
596 | /** |
||
597 | * Get twitterUrl. |
||
598 | * |
||
599 | * @return string |
||
600 | */ |
||
601 | public function getTwitterUrl() |
||
605 | |||
606 | /** |
||
607 | * Set twitterCreator. |
||
608 | * |
||
609 | * @param string $twitterCreator |
||
610 | * |
||
611 | * @return PageSeo |
||
612 | */ |
||
613 | public function setTwitterCreator($twitterCreator) |
||
619 | |||
620 | /** |
||
621 | * Get twitterCreator. |
||
622 | * |
||
623 | * @return string |
||
624 | */ |
||
625 | public function getTwitterCreator() |
||
629 | |||
630 | /** |
||
631 | * Set twitterTitle. |
||
632 | * |
||
633 | * @param string $twitterTitle |
||
634 | * |
||
635 | * @return PageSeo |
||
636 | */ |
||
637 | public function setTwitterTitle($twitterTitle) |
||
643 | |||
644 | /** |
||
645 | * Get twitterTitle. |
||
646 | * |
||
647 | * @return string |
||
648 | */ |
||
649 | public function getTwitterTitle() |
||
653 | |||
654 | /** |
||
655 | * Set twitterDescription. |
||
656 | * |
||
657 | * @param string $twitterDescription |
||
658 | * |
||
659 | * @return PageSeo |
||
660 | */ |
||
661 | public function setTwitterDescription($twitterDescription) |
||
667 | |||
668 | /** |
||
669 | * Get twitterDescription. |
||
670 | * |
||
671 | * @return string |
||
672 | */ |
||
673 | public function getTwitterDescription() |
||
677 | |||
678 | /** |
||
679 | * Set twitterImage. |
||
680 | * |
||
681 | * @param Image $twitterImage |
||
682 | * |
||
683 | * @return PageSeo |
||
684 | */ |
||
685 | public function setTwitterImage($twitterImage) |
||
691 | |||
692 | /** |
||
693 | * Get twitterImage. |
||
694 | * |
||
695 | * @return string |
||
696 | */ |
||
697 | public function getTwitterImage() |
||
701 | |||
702 | /** |
||
703 | * Set schemaPageType. |
||
704 | * |
||
705 | * @param string $schemaPageType |
||
706 | * |
||
707 | * @return PageSeo |
||
708 | */ |
||
709 | public function setSchemaPageType($schemaPageType) |
||
715 | |||
716 | /** |
||
717 | * Get schemaPageType. |
||
718 | * |
||
719 | * @return string |
||
720 | */ |
||
721 | public function getSchemaPageType() |
||
725 | |||
726 | /** |
||
727 | * Set schemaName. |
||
728 | * |
||
729 | * @param string $schemaName |
||
730 | * |
||
731 | * @return PageSeo |
||
732 | */ |
||
733 | public function setSchemaName($schemaName) |
||
739 | |||
740 | /** |
||
741 | * Get schemaName. |
||
742 | * |
||
743 | * @return string |
||
744 | */ |
||
745 | public function getSchemaName() |
||
749 | |||
750 | /** |
||
751 | * Set schemaDescription. |
||
752 | * |
||
753 | * @param string $schemaDescription |
||
754 | * |
||
755 | * @return PageSeo |
||
756 | */ |
||
757 | public function setSchemaDescription($schemaDescription) |
||
763 | |||
764 | /** |
||
765 | * Get schemaDescription. |
||
766 | * |
||
767 | * @return string |
||
768 | */ |
||
769 | public function getSchemaDescription() |
||
773 | |||
774 | /** |
||
775 | * Set schemaImage. |
||
776 | * |
||
777 | * @param Image $schemaImage |
||
778 | * |
||
779 | * @return PageSeo |
||
780 | */ |
||
781 | public function setSchemaImage($schemaImage) |
||
787 | |||
788 | /** |
||
789 | * Get schemaImage. |
||
790 | * |
||
791 | * @return string |
||
792 | */ |
||
793 | public function getSchemaImage() |
||
797 | |||
798 | /** |
||
799 | * Set metaRobotsIndex. |
||
800 | * |
||
801 | * @param string $metaRobotsIndex |
||
802 | * |
||
803 | * @return PageSeo |
||
804 | */ |
||
805 | public function setMetaRobotsIndex($metaRobotsIndex) |
||
811 | |||
812 | /** |
||
813 | * Get metaRobotsIndex. |
||
814 | * |
||
815 | * @return string |
||
816 | */ |
||
817 | public function getMetaRobotsIndex() |
||
821 | |||
822 | /** |
||
823 | * Set metaRobotsFollow. |
||
824 | * |
||
825 | * @param string $metaRobotsFollow |
||
826 | * |
||
827 | * @return PageSeo |
||
828 | */ |
||
829 | public function setMetaRobotsFollow($metaRobotsFollow) |
||
835 | |||
836 | /** |
||
837 | * Get metaRobotsFollow. |
||
838 | * |
||
839 | * @return string |
||
840 | */ |
||
841 | public function getMetaRobotsFollow() |
||
845 | |||
846 | /** |
||
847 | * Set metaRobotsAdvanced. |
||
848 | * |
||
849 | * @param string $metaRobotsAdvanced |
||
850 | * |
||
851 | * @return PageSeo |
||
852 | */ |
||
853 | public function setMetaRobotsAdvanced($metaRobotsAdvanced) |
||
859 | |||
860 | /** |
||
861 | * Get metaRobotsAdvanced. |
||
862 | * |
||
863 | * @return string |
||
864 | */ |
||
865 | public function getMetaRobotsAdvanced() |
||
869 | |||
870 | /** |
||
871 | * Set sitemapIndexed. |
||
872 | * |
||
873 | * @param bool $sitemapIndexed |
||
874 | * |
||
875 | * @return PageSeo |
||
876 | */ |
||
877 | public function setSitemapIndexed($sitemapIndexed) |
||
883 | |||
884 | /** |
||
885 | * Get sitemapIndexed. |
||
886 | * |
||
887 | * @return bool |
||
888 | */ |
||
889 | public function isSitemapIndexed() |
||
893 | |||
894 | /** |
||
895 | * Set sitemapPriority. |
||
896 | * |
||
897 | * @param float $sitemapPriority |
||
898 | * |
||
899 | * @return PageSeo |
||
900 | */ |
||
901 | public function setSitemapPriority($sitemapPriority) |
||
907 | |||
908 | /** |
||
909 | * Get sitemapPriority. |
||
910 | * |
||
911 | * @return float |
||
912 | */ |
||
913 | public function getSitemapPriority() |
||
917 | |||
918 | /** |
||
919 | * Set sitemapChangeFreq. |
||
920 | * |
||
921 | * @param float $sitemapChangeFreq |
||
922 | * |
||
923 | * @return PageSeo |
||
924 | */ |
||
925 | public function setSitemapChangeFreq($sitemapChangeFreq) |
||
931 | |||
932 | /** |
||
933 | * Get sitemapChangeFreq. |
||
934 | * |
||
935 | * @return float |
||
936 | */ |
||
937 | public function getSitemapChangeFreq() |
||
941 | |||
942 | /** |
||
943 | * Set relCanonical. |
||
944 | * |
||
945 | * @param string $relCanonical |
||
946 | * |
||
947 | * @return PageSeo |
||
948 | */ |
||
949 | public function setRelCanonical($relCanonical) |
||
955 | |||
956 | /** |
||
957 | * Get relCanonical. |
||
958 | * |
||
959 | * @return string |
||
960 | */ |
||
961 | public function getRelCanonical() |
||
965 | |||
966 | /** |
||
967 | * Set keyword. |
||
968 | * |
||
969 | * @param string $keyword |
||
970 | * |
||
971 | * @return PageSeo |
||
972 | */ |
||
973 | public function setKeyword($keyword) |
||
979 | |||
980 | /** |
||
981 | * Get keyword. |
||
982 | * |
||
983 | * @return string |
||
984 | */ |
||
985 | public function getKeyword() |
||
989 | |||
990 | public function setTranslatableLocale($locale) |
||
994 | |||
995 | /** |
||
996 | * @return string |
||
997 | */ |
||
998 | public function getLocale() |
||
1002 | } |
||
1003 |
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..