Complex classes like Property 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 Property, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Property |
||
| 18 | { |
||
| 19 | use EntityIdTrait; |
||
| 20 | use EntityMetaTrait; |
||
| 21 | use EntityTimestampableTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="properties") |
||
| 25 | * @ORM\JoinColumn(nullable=false) |
||
| 26 | */ |
||
| 27 | private $author; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @ORM\ManyToOne(targetEntity="App\Entity\DealType", inversedBy="properties") |
||
| 31 | * @ORM\JoinColumn(nullable=false) |
||
| 32 | */ |
||
| 33 | private $deal_type; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="properties") |
||
| 37 | * @ORM\JoinColumn(nullable=false) |
||
| 38 | */ |
||
| 39 | private $category; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @ORM\ManyToOne(targetEntity="App\Entity\City", inversedBy="properties") |
||
| 43 | * @ORM\JoinColumn(nullable=false) |
||
| 44 | */ |
||
| 45 | private $city; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @ORM\ManyToOne(targetEntity="App\Entity\Neighborhood", inversedBy="properties") |
||
| 49 | * @ORM\JoinColumn(nullable=true) |
||
| 50 | */ |
||
| 51 | private $neighborhood; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @ORM\Column(type="string", length=255) |
||
| 55 | */ |
||
| 56 | private $title; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 60 | */ |
||
| 61 | private $slug; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @ORM\Column(type="text") |
||
| 65 | */ |
||
| 66 | private $content; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @ORM\Column(type="smallint", nullable=true) |
||
| 70 | */ |
||
| 71 | private $bathrooms_number; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @ORM\Column(type="smallint", nullable=true) |
||
| 75 | */ |
||
| 76 | private $bedrooms_number; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @ORM\Column(type="smallint", nullable=true) |
||
| 80 | */ |
||
| 81 | private $max_guests; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @ORM\Column(type="string", length=255) |
||
| 85 | */ |
||
| 86 | private $address; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 90 | */ |
||
| 91 | private $latitude; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 95 | */ |
||
| 96 | private $longitude; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @ORM\Column(type="boolean", nullable=true) |
||
| 100 | */ |
||
| 101 | private $show_map; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @ORM\Column(type="integer", nullable=true) |
||
| 105 | */ |
||
| 106 | private $price; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 110 | */ |
||
| 111 | private $price_type; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @ORM\Column(type="boolean", nullable=true) |
||
| 115 | */ |
||
| 116 | private $available_now; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @ORM\Column(type="string", length=255, options={"default": "pending"}) |
||
| 120 | */ |
||
| 121 | private $state = 'published'; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @ORM\OneToMany(targetEntity="App\Entity\Photo", mappedBy="property", orphanRemoval=true) |
||
| 125 | * @ORM\OrderBy({"sort_order" = "ASC"}) |
||
| 126 | */ |
||
| 127 | private $photos; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @ORM\ManyToMany(targetEntity="App\Entity\Feature", inversedBy="properties") |
||
| 131 | */ |
||
| 132 | private $features; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @ORM\ManyToOne(targetEntity="App\Entity\Metro", inversedBy="properties") |
||
| 136 | * @ORM\JoinColumn(nullable=true) |
||
| 137 | */ |
||
| 138 | private $metro_station; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @ORM\Column(type="integer") |
||
| 142 | */ |
||
| 143 | private $priority_number; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @ORM\ManyToOne(targetEntity="App\Entity\District", inversedBy="properties") |
||
| 147 | * @ORM\JoinColumn(nullable=true) |
||
| 148 | */ |
||
| 149 | private $district; |
||
| 150 | |||
| 151 | public function __construct() |
||
| 156 | |||
| 157 | public function getAuthor(): ?User |
||
| 161 | |||
| 162 | public function setAuthor(?User $author): self |
||
| 168 | |||
| 169 | public function getDealType(): ?DealType |
||
| 173 | |||
| 174 | public function setDealType(?DealType $dealType): self |
||
| 180 | |||
| 181 | public function getCategory(): ?Category |
||
| 185 | |||
| 186 | public function setCategory(?Category $category): self |
||
| 192 | |||
| 193 | public function getCity(): ?City |
||
| 197 | |||
| 198 | public function setCity(?City $city): self |
||
| 204 | |||
| 205 | public function getTitle(): ?string |
||
| 209 | |||
| 210 | public function setTitle(string $title): self |
||
| 216 | |||
| 217 | public function getSlug(): ?string |
||
| 221 | |||
| 222 | public function setSlug(string $slug): self |
||
| 228 | |||
| 229 | public function getContent(): ?string |
||
| 233 | |||
| 234 | public function setContent(string $content): self |
||
| 240 | |||
| 241 | public function getBathroomsNumber(): ?int |
||
| 245 | |||
| 246 | public function setBathroomsNumber(?int $bathrooms_number): self |
||
| 252 | |||
| 253 | public function getBedroomsNumber(): ?int |
||
| 257 | |||
| 258 | public function setBedroomsNumber(?int $bedrooms_number): self |
||
| 264 | |||
| 265 | public function getAddress(): ?string |
||
| 269 | |||
| 270 | public function setAddress(string $address): self |
||
| 276 | |||
| 277 | public function getLatitude(): ?string |
||
| 281 | |||
| 282 | public function setLatitude(?string $latitude): self |
||
| 288 | |||
| 289 | public function getLongitude(): ?string |
||
| 293 | |||
| 294 | public function setLongitude(?string $longitude): self |
||
| 300 | |||
| 301 | public function getShowMap(): ?bool |
||
| 305 | |||
| 306 | public function setShowMap(?bool $show_map): self |
||
| 312 | |||
| 313 | public function getPrice(): ?int |
||
| 317 | |||
| 318 | public function setPrice(?int $price): self |
||
| 324 | |||
| 325 | public function getPriceType(): ?string |
||
| 329 | |||
| 330 | public function setPriceType(?string $price_type): self |
||
| 336 | |||
| 337 | public function getAvailableNow(): ?bool |
||
| 341 | |||
| 342 | public function setAvailableNow(?bool $available_now): self |
||
| 348 | |||
| 349 | public function getPhotos(): Collection |
||
| 353 | |||
| 354 | public function addPhoto(Photo $photo): self |
||
| 363 | |||
| 364 | public function removePhoto(Photo $photo): self |
||
| 376 | |||
| 377 | public function getNeighborhood(): ?Neighborhood |
||
| 381 | |||
| 382 | public function setNeighborhood(?Neighborhood $neighborhood): self |
||
| 388 | |||
| 389 | public function getFeatures(): Collection |
||
| 393 | |||
| 394 | public function addFeature(Feature $feature): self |
||
| 402 | |||
| 403 | public function removeFeature(Feature $feature): self |
||
| 411 | |||
| 412 | public function getMetroStation(): ?Metro |
||
| 416 | |||
| 417 | public function setMetroStation(?Metro $metro_station): self |
||
| 423 | |||
| 424 | public function getPriorityNumber(): ?int |
||
| 428 | |||
| 429 | public function setPriorityNumber(?int $priority_number): self |
||
| 435 | |||
| 436 | public function getDistrict(): ?District |
||
| 440 | |||
| 441 | public function setDistrict(?District $district): self |
||
| 447 | |||
| 448 | public function getMaxGuests(): ?int |
||
| 452 | |||
| 453 | public function setMaxGuests(?int $max_guests): self |
||
| 459 | |||
| 460 | public function getState(): ?string |
||
| 464 | |||
| 465 | public function setState(string $state): self |
||
| 471 | |||
| 472 | public function isPublished(): bool |
||
| 476 | } |
||
| 477 |