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 |
||
| 18 | class Property |
||
| 19 | { |
||
| 20 | use EntityIdTrait; |
||
| 21 | use EntityMetaTrait; |
||
| 22 | use EntityTimestampableTrait; |
||
| 23 | use EntityLocationTrait; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="properties") |
||
| 27 | * @ORM\JoinColumn(nullable=false) |
||
| 28 | */ |
||
| 29 | private $author; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @ORM\ManyToOne(targetEntity="App\Entity\DealType", inversedBy="properties") |
||
| 33 | * @ORM\JoinColumn(nullable=false) |
||
| 34 | */ |
||
| 35 | private $deal_type; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="properties") |
||
| 39 | * @ORM\JoinColumn(nullable=false) |
||
| 40 | */ |
||
| 41 | private $category; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @ORM\Column(type="string", length=255) |
||
| 45 | */ |
||
| 46 | private $title; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 50 | */ |
||
| 51 | private $slug; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @ORM\Column(type="text") |
||
| 55 | */ |
||
| 56 | private $content; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @ORM\Column(type="smallint", nullable=true) |
||
| 60 | */ |
||
| 61 | private $bathrooms_number; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @ORM\Column(type="smallint", nullable=true) |
||
| 65 | */ |
||
| 66 | private $bedrooms_number; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @ORM\Column(type="smallint", nullable=true) |
||
| 70 | */ |
||
| 71 | private $max_guests; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @ORM\Column(type="boolean", nullable=true) |
||
| 75 | */ |
||
| 76 | private $show_map; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @ORM\Column(type="integer", nullable=true) |
||
| 80 | */ |
||
| 81 | private $price; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 85 | */ |
||
| 86 | private $price_type; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @ORM\Column(type="boolean", nullable=true) |
||
| 90 | */ |
||
| 91 | private $available_now; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @ORM\Column(type="string", length=255, options={"default": "pending"}) |
||
| 95 | */ |
||
| 96 | private $state = 'published'; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @ORM\OneToMany(targetEntity="App\Entity\Photo", mappedBy="property", orphanRemoval=true) |
||
| 100 | * @ORM\OrderBy({"sort_order" = "ASC"}) |
||
| 101 | */ |
||
| 102 | private $photos; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @ORM\ManyToMany(targetEntity="App\Entity\Feature", inversedBy="properties") |
||
| 106 | */ |
||
| 107 | private $features; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @ORM\Column(type="integer") |
||
| 111 | */ |
||
| 112 | private $priority_number; |
||
| 113 | |||
| 114 | public function __construct() |
||
| 119 | |||
| 120 | public function getAuthor(): ?User |
||
| 124 | |||
| 125 | public function setAuthor(?User $author): self |
||
| 131 | |||
| 132 | public function getDealType(): ?DealType |
||
| 136 | |||
| 137 | public function setDealType(?DealType $dealType): self |
||
| 143 | |||
| 144 | public function getCategory(): ?Category |
||
| 148 | |||
| 149 | public function setCategory(?Category $category): self |
||
| 155 | |||
| 156 | public function getTitle(): ?string |
||
| 160 | |||
| 161 | public function setTitle(string $title): self |
||
| 167 | |||
| 168 | public function getSlug(): ?string |
||
| 172 | |||
| 173 | public function setSlug(string $slug): self |
||
| 179 | |||
| 180 | public function getContent(): ?string |
||
| 184 | |||
| 185 | public function setContent(string $content): self |
||
| 191 | |||
| 192 | public function getBathroomsNumber(): ?int |
||
| 196 | |||
| 197 | public function setBathroomsNumber(?int $bathrooms_number): self |
||
| 203 | |||
| 204 | public function getBedroomsNumber(): ?int |
||
| 208 | |||
| 209 | public function setBedroomsNumber(?int $bedrooms_number): self |
||
| 215 | |||
| 216 | public function getShowMap(): ?bool |
||
| 220 | |||
| 221 | public function setShowMap(?bool $show_map): self |
||
| 227 | |||
| 228 | public function getPrice(): ?int |
||
| 232 | |||
| 233 | public function setPrice(?int $price): self |
||
| 239 | |||
| 240 | public function getPriceType(): ?string |
||
| 244 | |||
| 245 | public function setPriceType(?string $price_type): self |
||
| 251 | |||
| 252 | public function getAvailableNow(): ?bool |
||
| 256 | |||
| 257 | public function setAvailableNow(?bool $available_now): self |
||
| 263 | |||
| 264 | public function getPhotos(): Collection |
||
| 268 | |||
| 269 | public function addPhoto(Photo $photo): self |
||
| 278 | |||
| 279 | public function removePhoto(Photo $photo): self |
||
| 291 | |||
| 292 | public function getFeatures(): Collection |
||
| 296 | |||
| 297 | public function addFeature(Feature $feature): self |
||
| 305 | |||
| 306 | public function removeFeature(Feature $feature): self |
||
| 314 | |||
| 315 | public function getPriorityNumber(): ?int |
||
| 319 | |||
| 320 | public function setPriorityNumber(?int $priority_number): self |
||
| 326 | |||
| 327 | public function getMaxGuests(): ?int |
||
| 331 | |||
| 332 | public function setMaxGuests(?int $max_guests): self |
||
| 338 | |||
| 339 | public function getState(): ?string |
||
| 343 | |||
| 344 | public function setState(string $state): self |
||
| 350 | |||
| 351 | public function isPublished(): bool |
||
| 355 | } |
||
| 356 |