| Total Complexity | 66 |
| Total Lines | 373 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Registration 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 Registration, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class Registration extends AbstractEntity |
||
| 24 | { |
||
| 25 | protected string $firstname = ''; |
||
| 26 | protected string $lastname = ''; |
||
| 27 | protected string $title = ''; |
||
| 28 | protected string $company = ''; |
||
| 29 | protected string $address = ''; |
||
| 30 | protected string $zip = ''; |
||
| 31 | protected string $city = ''; |
||
| 32 | protected string $country = ''; |
||
| 33 | protected string $phone = ''; |
||
| 34 | protected string $email = ''; |
||
| 35 | protected bool $ignoreNotifications = false; |
||
| 36 | protected string $gender = ''; |
||
| 37 | protected ?DateTime $dateOfBirth = null; |
||
| 38 | protected bool $accepttc = false; |
||
| 39 | protected bool $confirmed = false; |
||
| 40 | protected bool $paid = false; |
||
| 41 | protected string $notes = ''; |
||
| 42 | protected Event $event; |
||
| 43 | protected ?Registration $mainRegistration = null; |
||
| 44 | protected ?DateTime $confirmationUntil = null; |
||
| 45 | protected ?DateTime $registrationDate = null; |
||
| 46 | protected bool $hidden = false; |
||
| 47 | protected int $amountOfRegistrations = 1; |
||
| 48 | protected string $language = ''; |
||
| 49 | protected string $captcha = ''; |
||
| 50 | protected ?FrontendUser $feUser = null; |
||
| 51 | protected string $paymentmethod = ''; |
||
| 52 | protected string $paymentReference = ''; |
||
| 53 | protected bool $waitlist = false; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var ObjectStorage<FieldValue> |
||
| 57 | * @Extbase\ORM\Cascade("remove") |
||
| 58 | * @Extbase\ORM\Lazy |
||
| 59 | */ |
||
| 60 | protected ObjectStorage $fieldValues; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Registration constructor. |
||
| 64 | */ |
||
| 65 | public function __construct() |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Initialize all ObjectStorages as fetching an entity from the DB does not use the constructor |
||
| 72 | */ |
||
| 73 | public function initializeObject() |
||
| 74 | { |
||
| 75 | $this->fieldValues = $this->fieldValues ?? new ObjectStorage(); |
||
| 76 | } |
||
| 77 | |||
| 78 | public function getFirstname(): string |
||
| 79 | { |
||
| 80 | return $this->firstname; |
||
| 81 | } |
||
| 82 | |||
| 83 | public function setFirstname(string $firstname) |
||
| 84 | { |
||
| 85 | $this->firstname = $firstname; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function getLastname(): string |
||
| 89 | { |
||
| 90 | return $this->lastname; |
||
| 91 | } |
||
| 92 | |||
| 93 | public function setLastname(string $lastname) |
||
| 94 | { |
||
| 95 | $this->lastname = $lastname; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function getTitle(): string |
||
| 99 | { |
||
| 100 | return $this->title; |
||
| 101 | } |
||
| 102 | |||
| 103 | public function setTitle(string $title) |
||
| 104 | { |
||
| 105 | $this->title = $title; |
||
| 106 | } |
||
| 107 | |||
| 108 | public function getCompany(): string |
||
| 109 | { |
||
| 110 | return $this->company; |
||
| 111 | } |
||
| 112 | |||
| 113 | public function setCompany(string $company) |
||
| 114 | { |
||
| 115 | $this->company = $company; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function getAddress(): string |
||
| 119 | { |
||
| 120 | return $this->address; |
||
| 121 | } |
||
| 122 | |||
| 123 | public function setAddress(string $address) |
||
| 124 | { |
||
| 125 | $this->address = $address; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function getZip(): string |
||
| 129 | { |
||
| 130 | return $this->zip; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function setZip(string $zip) |
||
| 134 | { |
||
| 135 | $this->zip = $zip; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function getCity(): string |
||
| 139 | { |
||
| 140 | return $this->city; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function setCity(string $city) |
||
| 144 | { |
||
| 145 | $this->city = $city; |
||
| 146 | } |
||
| 147 | |||
| 148 | public function getCountry(): string |
||
| 149 | { |
||
| 150 | return $this->country; |
||
| 151 | } |
||
| 152 | |||
| 153 | public function setCountry(string $country) |
||
| 154 | { |
||
| 155 | $this->country = $country; |
||
| 156 | } |
||
| 157 | |||
| 158 | public function getPhone(): string |
||
| 159 | { |
||
| 160 | return $this->phone; |
||
| 161 | } |
||
| 162 | |||
| 163 | public function setPhone(string $phone) |
||
| 164 | { |
||
| 165 | $this->phone = $phone; |
||
| 166 | } |
||
| 167 | |||
| 168 | public function getEmail(): string |
||
| 171 | } |
||
| 172 | |||
| 173 | public function setEmail(string $email) |
||
| 174 | { |
||
| 175 | $this->email = trim($email); |
||
| 176 | } |
||
| 177 | |||
| 178 | public function isIgnoreNotifications(): bool |
||
| 181 | } |
||
| 182 | |||
| 183 | public function getIgnoreNotifications(): bool |
||
| 184 | { |
||
| 185 | return $this->ignoreNotifications; |
||
| 186 | } |
||
| 187 | |||
| 188 | public function setIgnoreNotifications(bool $ignoreNotifications) |
||
| 189 | { |
||
| 190 | $this->ignoreNotifications = $ignoreNotifications; |
||
| 191 | } |
||
| 192 | |||
| 193 | public function getGender(): string |
||
| 194 | { |
||
| 195 | return $this->gender; |
||
| 196 | } |
||
| 197 | |||
| 198 | public function setGender(string $gender) |
||
| 199 | { |
||
| 200 | $this->gender = $gender; |
||
| 201 | } |
||
| 202 | |||
| 203 | public function setDateOfBirth(?DateTime $dateOfBirth) |
||
| 204 | { |
||
| 205 | $this->dateOfBirth = $dateOfBirth; |
||
| 206 | } |
||
| 207 | |||
| 208 | public function getDateOfBirth(): ?DateTime |
||
| 209 | { |
||
| 210 | return $this->dateOfBirth; |
||
| 211 | } |
||
| 212 | |||
| 213 | public function getAccepttc(): bool |
||
| 214 | { |
||
| 215 | return $this->accepttc; |
||
| 216 | } |
||
| 217 | |||
| 218 | public function setAccepttc(bool $accepttc) |
||
| 219 | { |
||
| 220 | $this->accepttc = $accepttc; |
||
| 221 | } |
||
| 222 | |||
| 223 | public function getConfirmed(): bool |
||
| 224 | { |
||
| 225 | return $this->confirmed; |
||
| 226 | } |
||
| 227 | |||
| 228 | public function setConfirmed(bool $confirmed) |
||
| 229 | { |
||
| 230 | $this->confirmed = $confirmed; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function isConfirmed(): bool |
||
| 234 | { |
||
| 235 | return $this->confirmed; |
||
| 236 | } |
||
| 237 | |||
| 238 | public function getPaid(): bool |
||
| 239 | { |
||
| 240 | return $this->paid; |
||
| 241 | } |
||
| 242 | |||
| 243 | public function setPaid(bool $paid) |
||
| 244 | { |
||
| 245 | $this->paid = $paid; |
||
| 246 | } |
||
| 247 | |||
| 248 | public function isPaid(): bool |
||
| 249 | { |
||
| 250 | return $this->paid; |
||
| 251 | } |
||
| 252 | |||
| 253 | public function setEvent(Event $event) |
||
| 254 | { |
||
| 255 | $this->event = $event; |
||
| 256 | } |
||
| 257 | |||
| 258 | public function getEvent(): Event |
||
| 259 | { |
||
| 260 | return $this->event; |
||
| 261 | } |
||
| 262 | |||
| 263 | public function setMainRegistration(?Registration $registration) |
||
| 264 | { |
||
| 265 | $this->mainRegistration = $registration; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function getMainRegistration(): ?Registration |
||
| 269 | { |
||
| 270 | return $this->mainRegistration; |
||
| 271 | } |
||
| 272 | |||
| 273 | public function setNotes(string $notes) |
||
| 274 | { |
||
| 275 | $this->notes = $notes; |
||
| 276 | } |
||
| 277 | |||
| 278 | public function getNotes(): string |
||
| 279 | { |
||
| 280 | return $this->notes; |
||
| 281 | } |
||
| 282 | |||
| 283 | public function setConfirmationUntil(?DateTime $confirmationUntil) |
||
| 284 | { |
||
| 285 | $this->confirmationUntil = $confirmationUntil; |
||
| 286 | } |
||
| 287 | |||
| 288 | public function getConfirmationUntil(): ?DateTime |
||
| 289 | { |
||
| 290 | return $this->confirmationUntil; |
||
| 291 | } |
||
| 292 | |||
| 293 | public function getRegistrationDate(): ?DateTime |
||
| 294 | { |
||
| 295 | return $this->registrationDate; |
||
| 296 | } |
||
| 297 | |||
| 298 | public function setRegistrationDate(?DateTime $registrationDate) |
||
| 299 | { |
||
| 300 | $this->registrationDate = $registrationDate; |
||
| 301 | } |
||
| 302 | |||
| 303 | public function setHidden(bool $hidden) |
||
| 304 | { |
||
| 305 | $this->hidden = $hidden; |
||
| 306 | } |
||
| 307 | |||
| 308 | public function getHidden(): bool |
||
| 309 | { |
||
| 310 | return $this->hidden; |
||
| 311 | } |
||
| 312 | |||
| 313 | public function getAmountOfRegistrations(): int |
||
| 314 | { |
||
| 315 | return $this->amountOfRegistrations; |
||
| 316 | } |
||
| 317 | |||
| 318 | public function setAmountOfRegistrations(int $amountOfRegistrations) |
||
| 319 | { |
||
| 320 | $this->amountOfRegistrations = $amountOfRegistrations; |
||
| 321 | } |
||
| 322 | |||
| 323 | public function getLanguage(): string |
||
| 324 | { |
||
| 325 | return $this->language; |
||
| 326 | } |
||
| 327 | |||
| 328 | public function setLanguage(string $language) |
||
| 329 | { |
||
| 330 | $this->language = $language; |
||
| 331 | } |
||
| 332 | |||
| 333 | public function getCaptcha(): string |
||
| 334 | { |
||
| 335 | return $this->captcha; |
||
| 336 | } |
||
| 337 | |||
| 338 | public function setCaptcha(string $captcha) |
||
| 339 | { |
||
| 340 | $this->captcha = $captcha; |
||
| 341 | } |
||
| 342 | |||
| 343 | public function getFeUser(): ?FrontendUser |
||
| 344 | { |
||
| 345 | return $this->feUser; |
||
| 346 | } |
||
| 347 | |||
| 348 | public function setFeUser(?FrontendUser $feUser) |
||
| 349 | { |
||
| 350 | $this->feUser = $feUser; |
||
| 351 | } |
||
| 352 | |||
| 353 | public function getPaymentmethod(): string |
||
| 354 | { |
||
| 355 | return $this->paymentmethod; |
||
| 356 | } |
||
| 357 | |||
| 358 | public function setPaymentmethod(string $paymentmethod) |
||
| 359 | { |
||
| 360 | $this->paymentmethod = $paymentmethod; |
||
| 361 | } |
||
| 362 | |||
| 363 | public function getPaymentReference(): string |
||
| 364 | { |
||
| 365 | return $this->paymentReference; |
||
| 366 | } |
||
| 367 | |||
| 368 | public function setPaymentReference(string $paymentReference) |
||
| 369 | { |
||
| 370 | $this->paymentReference = $paymentReference; |
||
| 371 | } |
||
| 372 | |||
| 373 | public function getWaitlist(): bool |
||
| 376 | } |
||
| 377 | |||
| 378 | public function setWaitlist(bool $waitlist) |
||
| 379 | { |
||
| 380 | $this->waitlist = $waitlist; |
||
| 381 | } |
||
| 382 | |||
| 383 | public function getFieldValues(): ?ObjectStorage |
||
| 384 | { |
||
| 385 | return $this->fieldValues; |
||
| 386 | } |
||
| 387 | |||
| 388 | public function setFieldValues(?ObjectStorage $fieldValues) |
||
| 389 | { |
||
| 390 | $this->fieldValues = $fieldValues; |
||
| 391 | } |
||
| 392 | |||
| 393 | public function getFullname(): string |
||
| 394 | { |
||
| 395 | return $this->firstname . ' ' . $this->lastname; |
||
| 396 | } |
||
| 397 | } |
||
| 398 |