| Total Complexity | 42 |
| Total Lines | 323 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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.
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 EntityLocationTrait; |
||
| 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\Column(type="string", length=255, nullable=true) |
||
| 43 | */ |
||
| 44 | private $slug; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @ORM\Column(type="smallint", nullable=true) |
||
| 48 | */ |
||
| 49 | private $bathrooms_number; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @ORM\Column(type="smallint", nullable=true) |
||
| 53 | */ |
||
| 54 | private $bedrooms_number; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @ORM\Column(type="smallint", nullable=true) |
||
| 58 | */ |
||
| 59 | private $max_guests; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @ORM\Column(type="boolean", nullable=true) |
||
| 63 | */ |
||
| 64 | private $show_map; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @ORM\Column(type="integer", nullable=true) |
||
| 68 | */ |
||
| 69 | private $price; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @ORM\Column(type="string", length=255, nullable=true) |
||
| 73 | */ |
||
| 74 | private $price_type; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @ORM\Column(type="boolean", nullable=true) |
||
| 78 | */ |
||
| 79 | private $available_now; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @ORM\Column(type="string", length=255, options={"default": "pending"}) |
||
| 83 | */ |
||
| 84 | private $state = 'published'; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @ORM\OneToMany(targetEntity="App\Entity\Photo", mappedBy="property", orphanRemoval=true) |
||
| 88 | * @ORM\OrderBy({"sort_order" = "ASC"}) |
||
| 89 | */ |
||
| 90 | private $photos; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @ORM\ManyToMany(targetEntity="App\Entity\Feature", inversedBy="properties") |
||
| 94 | */ |
||
| 95 | private $features; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @ORM\Column(type="integer") |
||
| 99 | */ |
||
| 100 | private $priority_number; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @ORM\OneToOne(targetEntity=PropertyDescription::class, mappedBy="property", cascade={"persist", "remove"}) |
||
| 104 | */ |
||
| 105 | private $propertyDescription; |
||
| 106 | |||
| 107 | public function __construct() |
||
| 108 | { |
||
| 109 | $this->photos = new ArrayCollection(); |
||
| 110 | $this->features = new ArrayCollection(); |
||
| 111 | } |
||
| 112 | |||
| 113 | public function getAuthor(): ?User |
||
| 114 | { |
||
| 115 | return $this->author; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function setAuthor(?User $author): self |
||
| 119 | { |
||
| 120 | $this->author = $author; |
||
| 121 | |||
| 122 | return $this; |
||
| 123 | } |
||
| 124 | |||
| 125 | public function getDealType(): ?DealType |
||
| 126 | { |
||
| 127 | return $this->deal_type; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function setDealType(?DealType $dealType): self |
||
| 131 | { |
||
| 132 | $this->deal_type = $dealType; |
||
| 133 | |||
| 134 | return $this; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function getCategory(): ?Category |
||
| 138 | { |
||
| 139 | return $this->category; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function setCategory(?Category $category): self |
||
| 143 | { |
||
| 144 | $this->category = $category; |
||
| 145 | |||
| 146 | return $this; |
||
| 147 | } |
||
| 148 | |||
| 149 | public function getSlug(): ?string |
||
| 150 | { |
||
| 151 | return $this->slug; |
||
| 152 | } |
||
| 153 | |||
| 154 | public function setSlug(string $slug): self |
||
| 155 | { |
||
| 156 | $this->slug = $slug; |
||
| 157 | |||
| 158 | return $this; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function getBathroomsNumber(): ?int |
||
| 162 | { |
||
| 163 | return $this->bathrooms_number; |
||
| 164 | } |
||
| 165 | |||
| 166 | public function setBathroomsNumber(?int $bathrooms_number): self |
||
| 167 | { |
||
| 168 | $this->bathrooms_number = $bathrooms_number; |
||
| 169 | |||
| 170 | return $this; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function getBedroomsNumber(): ?int |
||
| 174 | { |
||
| 175 | return $this->bedrooms_number; |
||
| 176 | } |
||
| 177 | |||
| 178 | public function setBedroomsNumber(?int $bedrooms_number): self |
||
| 179 | { |
||
| 180 | $this->bedrooms_number = $bedrooms_number; |
||
| 181 | |||
| 182 | return $this; |
||
| 183 | } |
||
| 184 | |||
| 185 | public function getShowMap(): ?bool |
||
| 186 | { |
||
| 187 | return $this->show_map; |
||
| 188 | } |
||
| 189 | |||
| 190 | public function setShowMap(?bool $show_map): self |
||
| 191 | { |
||
| 192 | $this->show_map = $show_map; |
||
| 193 | |||
| 194 | return $this; |
||
| 195 | } |
||
| 196 | |||
| 197 | public function getPrice(): ?int |
||
| 198 | { |
||
| 199 | return $this->price; |
||
| 200 | } |
||
| 201 | |||
| 202 | public function setPrice(?int $price): self |
||
| 203 | { |
||
| 204 | $this->price = $price; |
||
| 205 | |||
| 206 | return $this; |
||
| 207 | } |
||
| 208 | |||
| 209 | public function getPriceType(): ?string |
||
| 210 | { |
||
| 211 | return $this->price_type; |
||
| 212 | } |
||
| 213 | |||
| 214 | public function setPriceType(?string $price_type): self |
||
| 215 | { |
||
| 216 | $this->price_type = $price_type; |
||
| 217 | |||
| 218 | return $this; |
||
| 219 | } |
||
| 220 | |||
| 221 | public function getAvailableNow(): ?bool |
||
| 224 | } |
||
| 225 | |||
| 226 | public function setAvailableNow(?bool $available_now): self |
||
| 227 | { |
||
| 228 | $this->available_now = $available_now; |
||
| 229 | |||
| 230 | return $this; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function getPhotos(): Collection |
||
| 234 | { |
||
| 235 | return $this->photos; |
||
| 236 | } |
||
| 237 | |||
| 238 | public function addPhoto(Photo $photo): self |
||
| 239 | { |
||
| 240 | if (!$this->photos->contains($photo)) { |
||
| 241 | $this->photos[] = $photo; |
||
| 242 | $photo->setProperty($this); |
||
| 243 | } |
||
| 244 | |||
| 245 | return $this; |
||
| 246 | } |
||
| 247 | |||
| 248 | public function removePhoto(Photo $photo): self |
||
| 249 | { |
||
| 250 | if ($this->photos->contains($photo)) { |
||
| 251 | $this->photos->removeElement($photo); |
||
| 252 | // set the owning side to null (unless already changed) |
||
| 253 | if ($photo->getProperty() === $this) { |
||
| 254 | $photo->setProperty(null); |
||
| 255 | } |
||
| 256 | } |
||
| 257 | |||
| 258 | return $this; |
||
| 259 | } |
||
| 260 | |||
| 261 | public function getFeatures(): Collection |
||
| 262 | { |
||
| 263 | return $this->features; |
||
| 264 | } |
||
| 265 | |||
| 266 | public function addFeature(Feature $feature): self |
||
| 267 | { |
||
| 268 | if (!$this->features->contains($feature)) { |
||
| 269 | $this->features[] = $feature; |
||
| 270 | } |
||
| 271 | |||
| 272 | return $this; |
||
| 273 | } |
||
| 274 | |||
| 275 | public function removeFeature(Feature $feature): self |
||
| 276 | { |
||
| 277 | if ($this->features->contains($feature)) { |
||
| 278 | $this->features->removeElement($feature); |
||
| 279 | } |
||
| 280 | |||
| 281 | return $this; |
||
| 282 | } |
||
| 283 | |||
| 284 | public function getPriorityNumber(): ?int |
||
| 285 | { |
||
| 286 | return $this->priority_number; |
||
| 287 | } |
||
| 288 | |||
| 289 | public function setPriorityNumber(?int $priority_number): self |
||
| 290 | { |
||
| 291 | $this->priority_number = $priority_number; |
||
| 292 | |||
| 293 | return $this; |
||
| 294 | } |
||
| 295 | |||
| 296 | public function getMaxGuests(): ?int |
||
| 297 | { |
||
| 298 | return $this->max_guests; |
||
| 299 | } |
||
| 300 | |||
| 301 | public function setMaxGuests(?int $max_guests): self |
||
| 302 | { |
||
| 303 | $this->max_guests = $max_guests; |
||
| 304 | |||
| 305 | return $this; |
||
| 306 | } |
||
| 307 | |||
| 308 | public function getState(): ?string |
||
| 309 | { |
||
| 310 | return $this->state; |
||
| 311 | } |
||
| 312 | |||
| 313 | public function setState(string $state): self |
||
| 314 | { |
||
| 315 | $this->state = $state; |
||
| 316 | |||
| 317 | return $this; |
||
| 318 | } |
||
| 319 | |||
| 320 | public function isPublished(): bool |
||
| 321 | { |
||
| 322 | return 'published' === $this->state; |
||
| 323 | } |
||
| 324 | |||
| 325 | public function getPropertyDescription(): ?PropertyDescription |
||
| 328 | } |
||
| 329 | |||
| 330 | public function setPropertyDescription(PropertyDescription $propertyDescription): self |
||
| 331 | { |
||
| 332 | // set the owning side of the relation if necessary |
||
| 333 | if ($propertyDescription->getProperty() !== $this) { |
||
| 334 | $propertyDescription->setProperty($this); |
||
| 335 | } |
||
| 336 | |||
| 337 | $this->propertyDescription = $propertyDescription; |
||
| 338 | |||
| 339 | return $this; |
||
| 340 | } |
||
| 341 | } |
||
| 342 |