| Total Complexity | 42 |
| Total Lines | 246 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like SubscriptionPlan 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 SubscriptionPlan, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class SubscriptionPlan implements CrudEntityInterface |
||
| 22 | { |
||
| 23 | private $id; |
||
| 24 | |||
| 25 | private bool $public = false; |
||
| 26 | |||
| 27 | private string $name; |
||
| 28 | |||
| 29 | private ?string $codeName = null; |
||
| 30 | |||
| 31 | private ?string $externalReference = null; |
||
| 32 | |||
| 33 | private ?string $paymentProviderDetailsLink = null; |
||
| 34 | |||
| 35 | private array|Collection $limits; |
||
| 36 | |||
| 37 | private bool $perSeat; |
||
| 38 | |||
| 39 | private bool $free; |
||
| 40 | |||
| 41 | private int $userCount; |
||
| 42 | |||
| 43 | private ?bool $hasTrial = false; |
||
| 44 | |||
| 45 | private ?int $trialLengthDays = 0; |
||
| 46 | |||
| 47 | private array|Collection $features; |
||
| 48 | |||
| 49 | private array|Collection $prices; |
||
| 50 | |||
| 51 | private Product $product; |
||
| 52 | |||
| 53 | public function __construct() |
||
| 54 | { |
||
| 55 | $this->limits = new ArrayCollection(); |
||
| 56 | $this->features = new ArrayCollection(); |
||
| 57 | $this->prices = new ArrayCollection(); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @return mixed |
||
| 62 | */ |
||
| 63 | public function getId() |
||
| 64 | { |
||
| 65 | return $this->id; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param mixed $id |
||
| 70 | */ |
||
| 71 | public function setId($id): void |
||
| 72 | { |
||
| 73 | $this->id = $id; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function isPublic(): bool |
||
| 77 | { |
||
| 78 | return $this->public; |
||
| 79 | } |
||
| 80 | |||
| 81 | public function setPublic(bool $public): void |
||
| 82 | { |
||
| 83 | $this->public = $public; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function getName(): string |
||
| 87 | { |
||
| 88 | return $this->name; |
||
| 89 | } |
||
| 90 | |||
| 91 | public function setName(string $name): void |
||
| 92 | { |
||
| 93 | $this->name = $name; |
||
| 94 | } |
||
| 95 | |||
| 96 | public function getCodeName(): ?string |
||
| 97 | { |
||
| 98 | return $this->codeName; |
||
| 99 | } |
||
| 100 | |||
| 101 | public function setCodeName(?string $codeName): void |
||
| 102 | { |
||
| 103 | $this->codeName = $codeName; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public function getExternalReference(): ?string |
||
| 110 | { |
||
| 111 | return $this->externalReference; |
||
| 112 | } |
||
| 113 | |||
| 114 | public function setExternalReference(string $externalReference): void |
||
| 115 | { |
||
| 116 | $this->externalReference = $externalReference; |
||
| 117 | } |
||
| 118 | |||
| 119 | public function hasExternalReference(): bool |
||
| 120 | { |
||
| 121 | return isset($this->externalReference); |
||
| 122 | } |
||
| 123 | |||
| 124 | public function getPaymentProviderDetailsLink(): ?string |
||
| 125 | { |
||
| 126 | return $this->paymentProviderDetailsLink; |
||
| 127 | } |
||
| 128 | |||
| 129 | public function setPaymentProviderDetailsLink(?string $paymentProviderDetailsLink): void |
||
| 130 | { |
||
| 131 | $this->paymentProviderDetailsLink = $paymentProviderDetailsLink; |
||
| 132 | } |
||
| 133 | |||
| 134 | public function getLimits(): Collection|array |
||
| 135 | { |
||
| 136 | return $this->limits; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param SubscriptionPlanLimit[]|Collection $limits |
||
| 141 | */ |
||
| 142 | public function setLimits(Collection|array $limits): void |
||
| 143 | { |
||
| 144 | $this->limits = $limits; |
||
| 145 | } |
||
| 146 | |||
| 147 | public function addLimit(SubscriptionPlanLimit $limit): void |
||
| 148 | { |
||
| 149 | if (!$this->limits->contains($limit)) { |
||
| 150 | $limit->setSubscriptionPlan($this); |
||
| 151 | $this->limits->add($limit); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | public function removeLimit(SubscriptionPlanLimit $limit): void |
||
| 156 | { |
||
| 157 | $this->limits->removeElement($limit); |
||
| 158 | } |
||
| 159 | |||
| 160 | public function addFeature(SubscriptionFeature $subscriptionFeature): void |
||
| 161 | { |
||
| 162 | if (!$this->features->contains($subscriptionFeature)) { |
||
| 163 | $this->features->add($subscriptionFeature); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | public function removeFeature(SubscriptionFeature $subscriptionFeature): void |
||
| 168 | { |
||
| 169 | $this->features->removeElement($subscriptionFeature); |
||
| 170 | } |
||
| 171 | |||
| 172 | public function addPrice(Price $price): void |
||
| 173 | { |
||
| 174 | if (!$this->prices->contains($price)) { |
||
| 175 | $this->prices->add($price); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | public function removePrice(Price $price): void |
||
| 180 | { |
||
| 181 | $this->prices->removeElement($price); |
||
| 182 | } |
||
| 183 | |||
| 184 | public function getPrices(): Collection|array |
||
| 185 | { |
||
| 186 | return $this->prices; |
||
| 187 | } |
||
| 188 | |||
| 189 | public function setPrices(Collection|array $prices): void |
||
| 190 | { |
||
| 191 | $this->prices = $prices; |
||
| 192 | } |
||
| 193 | |||
| 194 | public function getDisplayName(): string |
||
| 195 | { |
||
| 196 | return $this->name; |
||
| 197 | } |
||
| 198 | |||
| 199 | public function isPerSeat(): bool |
||
| 200 | { |
||
| 201 | return $this->perSeat; |
||
| 202 | } |
||
| 203 | |||
| 204 | public function setPerSeat(bool $perSeat): void |
||
| 205 | { |
||
| 206 | $this->perSeat = $perSeat; |
||
| 207 | } |
||
| 208 | |||
| 209 | public function isFree(): bool |
||
| 210 | { |
||
| 211 | return $this->free; |
||
| 212 | } |
||
| 213 | |||
| 214 | public function setFree(bool $free): void |
||
| 215 | { |
||
| 216 | $this->free = $free; |
||
| 217 | } |
||
| 218 | |||
| 219 | public function getUserCount(): int |
||
| 220 | { |
||
| 221 | return $this->userCount; |
||
| 222 | } |
||
| 223 | |||
| 224 | public function setUserCount(int $userCount): void |
||
| 227 | } |
||
| 228 | |||
| 229 | public function getFeatures(): Collection|array |
||
| 230 | { |
||
| 231 | return $this->features; |
||
| 232 | } |
||
| 233 | |||
| 234 | public function setFeatures(Collection|array $features): void |
||
| 235 | { |
||
| 236 | $this->features = $features; |
||
| 237 | } |
||
| 238 | |||
| 239 | public function getProduct(): Product |
||
| 240 | { |
||
| 241 | return $this->product; |
||
| 242 | } |
||
| 243 | |||
| 244 | public function setProduct(Product $product): void |
||
| 245 | { |
||
| 246 | $this->product = $product; |
||
| 247 | } |
||
| 248 | |||
| 249 | public function getHasTrial(): bool |
||
| 252 | } |
||
| 253 | |||
| 254 | public function setHasTrial(?bool $hasTrial): void |
||
| 255 | { |
||
| 256 | $this->hasTrial = $hasTrial; |
||
| 257 | } |
||
| 258 | |||
| 259 | public function getTrialLengthDays(): int |
||
| 260 | { |
||
| 261 | return (int) $this->trialLengthDays; |
||
| 262 | } |
||
| 263 | |||
| 264 | public function setTrialLengthDays(?int $trialLengthDays): void |
||
| 267 | } |
||
| 268 | } |
||
| 269 |