Complex classes like ArticleViewDocument 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 ArticleViewDocument, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class ArticleViewDocument implements ArticleViewDocumentInterface |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | * |
||
| 30 | * @Id |
||
| 31 | */ |
||
| 32 | protected $id; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | * |
||
| 37 | * @Property(type="string", options={"analyzer": "keyword"}) |
||
| 38 | */ |
||
| 39 | protected $uuid; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | * |
||
| 44 | * @Property(type="string", options={"analyzer": "keyword"}) |
||
| 45 | */ |
||
| 46 | protected $locale; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string |
||
| 50 | * |
||
| 51 | * @Property( |
||
| 52 | * type="string", |
||
| 53 | * options={ |
||
| 54 | * "fields":{ |
||
| 55 | * "raw":{"type":"string", "index":"not_analyzed"}, |
||
| 56 | * "value":{"type":"string"} |
||
| 57 | * } |
||
| 58 | * } |
||
| 59 | * ) |
||
| 60 | */ |
||
| 61 | protected $title; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | * |
||
| 66 | * @Property( |
||
| 67 | * type="string", |
||
| 68 | * options={ |
||
| 69 | * "analyzer": "pathAnalyzer", |
||
| 70 | * "fields":{ |
||
| 71 | * "raw":{"type":"string", "index":"not_analyzed"}, |
||
| 72 | * "value":{"type":"string"} |
||
| 73 | * } |
||
| 74 | * } |
||
| 75 | * ) |
||
| 76 | */ |
||
| 77 | protected $routePath; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | * |
||
| 82 | * @Property(type="string", options={"analyzer": "keyword"}) |
||
| 83 | */ |
||
| 84 | protected $parentPageUuid; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var string |
||
| 88 | * |
||
| 89 | * @Property( |
||
| 90 | * type="string", |
||
| 91 | * options={ |
||
| 92 | * "analyzer":"keyword" |
||
| 93 | * } |
||
| 94 | * ) |
||
| 95 | */ |
||
| 96 | protected $type; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var string |
||
| 100 | * |
||
| 101 | * @Property( |
||
| 102 | * type="string", |
||
| 103 | * options={ |
||
| 104 | * "analyzer":"keyword" |
||
| 105 | * } |
||
| 106 | * ) |
||
| 107 | */ |
||
| 108 | protected $typeTranslation; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var string |
||
| 112 | * |
||
| 113 | * @Property( |
||
| 114 | * type="string", |
||
| 115 | * options={ |
||
| 116 | * "analyzer":"keyword" |
||
| 117 | * } |
||
| 118 | * ) |
||
| 119 | */ |
||
| 120 | protected $structureType; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var string |
||
| 124 | * |
||
| 125 | * @Property( |
||
| 126 | * type="string", |
||
| 127 | * options={ |
||
| 128 | * "fields":{ |
||
| 129 | * "raw":{"type":"string", "index":"not_analyzed"}, |
||
| 130 | * "value":{"type":"string"} |
||
| 131 | * } |
||
| 132 | * } |
||
| 133 | * ) |
||
| 134 | */ |
||
| 135 | protected $changerFullName; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var string |
||
| 139 | * |
||
| 140 | * @Property( |
||
| 141 | * type="string", |
||
| 142 | * options={ |
||
| 143 | * "fields":{ |
||
| 144 | * "raw":{"type":"string", "index":"not_analyzed"}, |
||
| 145 | * "value":{"type":"string"} |
||
| 146 | * } |
||
| 147 | * } |
||
| 148 | * ) |
||
| 149 | */ |
||
| 150 | protected $creatorFullName; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var \DateTime |
||
| 154 | * |
||
| 155 | * @Property(type="date") |
||
| 156 | */ |
||
| 157 | protected $changed; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var \DateTime |
||
| 161 | * |
||
| 162 | * @Property(type="date") |
||
| 163 | */ |
||
| 164 | protected $created; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @var ExcerptViewObject |
||
| 168 | * |
||
| 169 | * @Embedded(class="SuluArticleBundle:ExcerptViewObject") |
||
| 170 | */ |
||
| 171 | protected $excerpt; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var SeoViewObject |
||
| 175 | * |
||
| 176 | * @Embedded(class="SuluArticleBundle:SeoViewObject") |
||
| 177 | */ |
||
| 178 | protected $seo; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @var \DateTime |
||
| 182 | * |
||
| 183 | * @Property(type="date") |
||
| 184 | */ |
||
| 185 | protected $authored; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @var string |
||
| 189 | * |
||
| 190 | * @Property( |
||
| 191 | * type="string", |
||
| 192 | * options={ |
||
| 193 | * "fields":{ |
||
| 194 | * "raw":{"type":"string", "index":"not_analyzed"}, |
||
| 195 | * "value":{"type":"string"} |
||
| 196 | * } |
||
| 197 | * } |
||
| 198 | * ) |
||
| 199 | */ |
||
| 200 | protected $authorFullName; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @var string |
||
| 204 | * |
||
| 205 | * @Property(type="string") |
||
| 206 | */ |
||
| 207 | protected $teaserDescription = ''; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @var int |
||
| 211 | * |
||
| 212 | * @Property(type="integer") |
||
| 213 | */ |
||
| 214 | protected $teaserMediaId; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @var \DateTime |
||
| 218 | * |
||
| 219 | * @Property(type="date") |
||
| 220 | */ |
||
| 221 | protected $published; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @var bool |
||
| 225 | * |
||
| 226 | * @Property(type="boolean") |
||
| 227 | */ |
||
| 228 | protected $publishedState; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @var LocalizationStateViewObject |
||
| 232 | * |
||
| 233 | * @Embedded(class="SuluArticleBundle:LocalizationStateViewObject") |
||
| 234 | */ |
||
| 235 | protected $localizationState; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @var string |
||
| 239 | * |
||
| 240 | * @Property(type="string") |
||
| 241 | */ |
||
| 242 | protected $authorId; |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @var string |
||
| 246 | * |
||
| 247 | * @Property(type="string") |
||
| 248 | */ |
||
| 249 | protected $creatorContactId; |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @var string |
||
| 253 | * |
||
| 254 | * @Property(type="string") |
||
| 255 | */ |
||
| 256 | protected $changerContactId; |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @var ArticlePageViewObject[] |
||
| 260 | * |
||
| 261 | * @Embedded(class="SuluArticleBundle:ArticlePageViewObject", multiple=true) |
||
| 262 | */ |
||
| 263 | protected $pages = []; |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @var string |
||
| 267 | 56 | * |
|
| 268 | * @Property(type="string", options={"index":"not_analyzed"}) |
||
| 269 | 56 | */ |
|
| 270 | 56 | protected $contentData; |
|
| 271 | |||
| 272 | /** |
||
| 273 | * @var \ArrayObject |
||
| 274 | */ |
||
| 275 | 52 | protected $content; |
|
| 276 | |||
| 277 | 52 | /** |
|
| 278 | * @var \ArrayObject |
||
| 279 | */ |
||
| 280 | protected $view; |
||
| 281 | |||
| 282 | /** |
||
| 283 | 52 | * @param string $uuid |
|
| 284 | */ |
||
| 285 | 52 | public function __construct($uuid = null) |
|
| 289 | |||
| 290 | /** |
||
| 291 | * {@inheritdoc} |
||
| 292 | */ |
||
| 293 | 56 | public function getId() |
|
| 297 | |||
| 298 | /** |
||
| 299 | * {@inheritdoc} |
||
| 300 | */ |
||
| 301 | 52 | public function setId($id) |
|
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritdoc} |
||
| 310 | */ |
||
| 311 | 53 | public function getUuid() |
|
| 315 | |||
| 316 | /** |
||
| 317 | * {@inheritdoc} |
||
| 318 | */ |
||
| 319 | 55 | public function setUuid($uuid) |
|
| 325 | |||
| 326 | /** |
||
| 327 | * {@inheritdoc} |
||
| 328 | */ |
||
| 329 | 52 | public function getLocale() |
|
| 333 | |||
| 334 | /** |
||
| 335 | * {@inheritdoc} |
||
| 336 | */ |
||
| 337 | 52 | public function setLocale($locale) |
|
| 343 | |||
| 344 | /** |
||
| 345 | * {@inheritdoc} |
||
| 346 | */ |
||
| 347 | 52 | public function getTitle() |
|
| 351 | |||
| 352 | /** |
||
| 353 | * {@inheritdoc} |
||
| 354 | */ |
||
| 355 | 52 | public function setTitle($title) |
|
| 361 | |||
| 362 | /** |
||
| 363 | 52 | * {@inheritdoc} |
|
| 364 | */ |
||
| 365 | 52 | public function getRoutePath() |
|
| 369 | |||
| 370 | /** |
||
| 371 | 8 | * {@inheritdoc} |
|
| 372 | */ |
||
| 373 | 8 | public function setRoutePath($routePath) |
|
| 377 | |||
| 378 | /** |
||
| 379 | * {@inheritdoc} |
||
| 380 | */ |
||
| 381 | 52 | public function getParentPageUuid() |
|
| 385 | |||
| 386 | /** |
||
| 387 | * {@inheritdoc} |
||
| 388 | */ |
||
| 389 | 52 | public function setParentPageUuid($parentPageUuid) |
|
| 395 | |||
| 396 | /** |
||
| 397 | * {@inheritdoc} |
||
| 398 | */ |
||
| 399 | 52 | public function getType() |
|
| 403 | |||
| 404 | /** |
||
| 405 | * {@inheritdoc} |
||
| 406 | */ |
||
| 407 | 52 | public function setType($type) |
|
| 413 | |||
| 414 | /** |
||
| 415 | * {@inheritdoc} |
||
| 416 | */ |
||
| 417 | 52 | public function getTypeTranslation() |
|
| 421 | |||
| 422 | /** |
||
| 423 | * {@inheritdoc} |
||
| 424 | */ |
||
| 425 | 54 | public function setTypeTranslation($typeTranslation) |
|
| 431 | |||
| 432 | /** |
||
| 433 | * {@inheritdoc} |
||
| 434 | */ |
||
| 435 | 52 | public function getStructureType() |
|
| 439 | |||
| 440 | /** |
||
| 441 | * {@inheritdoc} |
||
| 442 | */ |
||
| 443 | 52 | public function setStructureType($structureType) |
|
| 449 | |||
| 450 | /** |
||
| 451 | * {@inheritdoc} |
||
| 452 | */ |
||
| 453 | 52 | public function getChangerFullName() |
|
| 457 | |||
| 458 | /** |
||
| 459 | * {@inheritdoc} |
||
| 460 | */ |
||
| 461 | 52 | public function setChangerFullName($changerFullName) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * {@inheritdoc} |
||
| 470 | */ |
||
| 471 | 52 | public function getCreatorFullName() |
|
| 475 | |||
| 476 | /** |
||
| 477 | * {@inheritdoc} |
||
| 478 | */ |
||
| 479 | 52 | public function setCreatorFullName($creatorFullName) |
|
| 485 | |||
| 486 | /** |
||
| 487 | * {@inheritdoc} |
||
| 488 | */ |
||
| 489 | 52 | public function getChanged() |
|
| 493 | |||
| 494 | /** |
||
| 495 | * {@inheritdoc} |
||
| 496 | */ |
||
| 497 | 52 | public function setChanged($changed) |
|
| 503 | |||
| 504 | /** |
||
| 505 | * {@inheritdoc} |
||
| 506 | */ |
||
| 507 | 52 | public function getCreated() |
|
| 511 | |||
| 512 | /** |
||
| 513 | * {@inheritdoc} |
||
| 514 | */ |
||
| 515 | 52 | public function setCreated($created) |
|
| 521 | |||
| 522 | /** |
||
| 523 | * {@inheritdoc} |
||
| 524 | */ |
||
| 525 | 52 | public function getExcerpt() |
|
| 529 | |||
| 530 | /** |
||
| 531 | * {@inheritdoc} |
||
| 532 | */ |
||
| 533 | 52 | public function setExcerpt(ExcerptViewObject $excerpt) |
|
| 539 | |||
| 540 | /** |
||
| 541 | * {@inheritdoc} |
||
| 542 | */ |
||
| 543 | 52 | public function getSeo() |
|
| 547 | |||
| 548 | /** |
||
| 549 | * {@inheritdoc} |
||
| 550 | */ |
||
| 551 | 52 | public function setSeo(SeoViewObject $seo) |
|
| 557 | |||
| 558 | /** |
||
| 559 | * {@inheritdoc} |
||
| 560 | */ |
||
| 561 | 52 | public function getAuthored() |
|
| 565 | |||
| 566 | /** |
||
| 567 | * {@inheritdoc} |
||
| 568 | */ |
||
| 569 | 52 | public function setAuthored(\DateTime $authored = null) |
|
| 575 | |||
| 576 | /** |
||
| 577 | * {@inheritdoc} |
||
| 578 | */ |
||
| 579 | 52 | public function getAuthorFullName() |
|
| 583 | |||
| 584 | /** |
||
| 585 | * {@inheritdoc} |
||
| 586 | */ |
||
| 587 | 46 | public function setAuthorFullName($authorFullName) |
|
| 593 | |||
| 594 | /** |
||
| 595 | * {@inheritdoc} |
||
| 596 | */ |
||
| 597 | 52 | public function getTeaserDescription() |
|
| 601 | |||
| 602 | /** |
||
| 603 | * {@inheritdoc} |
||
| 604 | */ |
||
| 605 | 1 | public function setTeaserDescription($teaserDescription) |
|
| 611 | |||
| 612 | /** |
||
| 613 | 52 | * {@inheritdoc} |
|
| 614 | */ |
||
| 615 | 52 | public function getTeaserMediaId() |
|
| 619 | |||
| 620 | /** |
||
| 621 | 52 | * {@inheritdoc} |
|
| 622 | */ |
||
| 623 | 52 | public function setTeaserMediaId($teaserMediaId) |
|
| 627 | |||
| 628 | /** |
||
| 629 | * {@inheritdoc} |
||
| 630 | */ |
||
| 631 | 52 | public function getPublished() |
|
| 635 | |||
| 636 | /** |
||
| 637 | * {@inheritdoc} |
||
| 638 | */ |
||
| 639 | 52 | public function setPublished(\DateTime $published = null) |
|
| 645 | |||
| 646 | /** |
||
| 647 | * {@inheritdoc} |
||
| 648 | */ |
||
| 649 | 52 | public function getPublishedState() |
|
| 653 | |||
| 654 | /** |
||
| 655 | * {@inheritdoc} |
||
| 656 | */ |
||
| 657 | 52 | public function setPublishedState($publishedState) |
|
| 663 | |||
| 664 | /** |
||
| 665 | * {@inheritdoc} |
||
| 666 | */ |
||
| 667 | 52 | public function getLocalizationState() |
|
| 671 | 52 | ||
| 672 | /** |
||
| 673 | * {@inheritdoc} |
||
| 674 | */ |
||
| 675 | public function setLocalizationState(LocalizationStateViewObject $localizationState) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * {@inheritdoc} |
||
| 684 | */ |
||
| 685 | 52 | public function setAuthorId($authorId) |
|
| 691 | |||
| 692 | /** |
||
| 693 | * {@inheritdoc} |
||
| 694 | */ |
||
| 695 | 52 | public function getAuthorId() |
|
| 699 | |||
| 700 | /** |
||
| 701 | * {@inheritdoc} |
||
| 702 | */ |
||
| 703 | 52 | public function setCreatorContactId($creatorContactId) |
|
| 709 | |||
| 710 | /** |
||
| 711 | * {@inheritdoc} |
||
| 712 | */ |
||
| 713 | 52 | public function getCreatorContactId() |
|
| 717 | |||
| 718 | /** |
||
| 719 | * {@inheritdoc} |
||
| 720 | */ |
||
| 721 | 52 | public function setChangerContactId($changerContactId) |
|
| 727 | |||
| 728 | /** |
||
| 729 | 52 | * {@inheritdoc} |
|
| 730 | */ |
||
| 731 | 52 | public function getChangerContactId() |
|
| 735 | |||
| 736 | /** |
||
| 737 | * {@inheritdoc} |
||
| 738 | */ |
||
| 739 | public function getPages() |
||
| 743 | |||
| 744 | /** |
||
| 745 | * {@inheritdoc} |
||
| 746 | */ |
||
| 747 | public function setPages(Collection $pages) |
||
| 753 | |||
| 754 | /** |
||
| 755 | * {@inheritdoc} |
||
| 756 | */ |
||
| 757 | public function getContentData() |
||
| 761 | |||
| 762 | /** |
||
| 763 | * {@inheritdoc} |
||
| 764 | */ |
||
| 765 | public function setContentData($contentData) |
||
| 771 | |||
| 772 | /** |
||
| 773 | * {@inheritdoc} |
||
| 774 | */ |
||
| 775 | public function getContent() |
||
| 779 | |||
| 780 | /** |
||
| 781 | * {@inheritdoc} |
||
| 782 | */ |
||
| 783 | public function setContent(\ArrayObject $content) |
||
| 789 | |||
| 790 | /** |
||
| 791 | * {@inheritdoc} |
||
| 792 | */ |
||
| 793 | public function getView() |
||
| 797 | |||
| 798 | /** |
||
| 799 | * {@inheritdoc} |
||
| 800 | */ |
||
| 801 | public function setView(\ArrayObject $view) |
||
| 807 | } |
||
| 808 |
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..