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