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