| Total Complexity | 40 |
| Total Lines | 529 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TenantTrait 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 TenantTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types = 1); |
||
| 10 | trait TenantTrait |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var int |
||
| 14 | * |
||
| 15 | * @ORM\Column(name="id", type="integer") |
||
| 16 | * @ORM\Id() |
||
| 17 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 18 | */ |
||
| 19 | private $id; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | * |
||
| 24 | * @ORM\Column(name="addon_key", type="string", length=255) |
||
| 25 | */ |
||
| 26 | private $addonKey; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | * |
||
| 31 | * @ORM\Column(name="client_key", type="string", length=255, unique=true) |
||
| 32 | */ |
||
| 33 | private $clientKey; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string|null |
||
| 37 | * |
||
| 38 | * @ORM\Column(name="oauth_client_id", type="string", length=255, nullable=true) |
||
| 39 | */ |
||
| 40 | private $oauthClientId; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | private $username; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string |
||
| 49 | * |
||
| 50 | * @ORM\Column(name="public_key", type="string", length=255) |
||
| 51 | */ |
||
| 52 | private $publicKey; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | * |
||
| 57 | * @ORM\Column(name="shared_secret", type="string", length=255) |
||
| 58 | */ |
||
| 59 | private $sharedSecret; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | * |
||
| 64 | * @ORM\Column(name="server_version", type="string", length=255) |
||
| 65 | */ |
||
| 66 | private $serverVersion; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var string |
||
| 70 | * |
||
| 71 | * @ORM\Column(name="plugins_version", type="string", length=255) |
||
| 72 | */ |
||
| 73 | private $pluginsVersion; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var string |
||
| 77 | * |
||
| 78 | * @ORM\Column(name="base_url", type="string", length=255) |
||
| 79 | */ |
||
| 80 | private $baseUrl; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var string |
||
| 84 | * |
||
| 85 | * @ORM\Column(name="product_type", type="string", length=255) |
||
| 86 | */ |
||
| 87 | private $productType; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string |
||
| 91 | * |
||
| 92 | * @ORM\Column(name="description", type="string", length=255) |
||
| 93 | */ |
||
| 94 | private $description; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var string |
||
| 98 | * |
||
| 99 | * @ORM\Column(name="event_type", type="string", length=255) |
||
| 100 | */ |
||
| 101 | private $eventType; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var \DateTime |
||
| 105 | * |
||
| 106 | * @ORM\Column(name="created_at", type="datetime", nullable=false) |
||
| 107 | */ |
||
| 108 | private $createdAt; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var \DateTime |
||
| 112 | * |
||
| 113 | * @ORM\Column(name="updated_at", type="datetime", nullable=false) |
||
| 114 | */ |
||
| 115 | private $updatedAt; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var bool |
||
| 119 | * |
||
| 120 | * @ORM\Column(name="is_white_listed", type="boolean", options={"default":0}) |
||
| 121 | */ |
||
| 122 | private $isWhiteListed = false; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var \DateTime |
||
| 126 | * |
||
| 127 | * @ORM\Column(name="white_listed_until", type="datetime", nullable=true) |
||
| 128 | */ |
||
| 129 | private $whiteListedUntil; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @ORM\PrePersist() |
||
| 133 | * |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | public function setCreatedAt(): void |
||
| 137 | { |
||
| 138 | $this->createdAt = new \DateTime(); |
||
| 139 | $this->updatedAt = new \DateTime(); |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return \DateTime |
||
| 144 | */ |
||
| 145 | public function getCreatedAt(): \DateTime |
||
| 146 | { |
||
| 147 | return $this->createdAt; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @ORM\PreUpdate() |
||
| 152 | * |
||
| 153 | * @return void |
||
| 154 | */ |
||
| 155 | public function setUpdatedAt(): void |
||
| 156 | { |
||
| 157 | $this->updatedAt = new \DateTime(); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @return \DateTime |
||
| 162 | */ |
||
| 163 | public function getUpdatedAt(): \DateTime |
||
| 164 | { |
||
| 165 | return $this->updatedAt; |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Get id |
||
| 170 | * |
||
| 171 | * @return int|null |
||
| 172 | */ |
||
| 173 | public function getId(): ?int |
||
| 174 | { |
||
| 175 | return $this->id; |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Set addonKey |
||
| 180 | * |
||
| 181 | * @param string $addonKey |
||
| 182 | * |
||
| 183 | * @return TenantTrait|TenantInterface |
||
| 184 | */ |
||
| 185 | public function setAddonKey(string $addonKey): TenantInterface |
||
| 186 | { |
||
| 187 | $this->addonKey = $addonKey; |
||
| 188 | |||
| 189 | return $this; |
||
|
|
|||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get addonKey |
||
| 194 | * |
||
| 195 | * @return string|null |
||
| 196 | */ |
||
| 197 | public function getAddonKey(): ?string |
||
| 198 | { |
||
| 199 | return $this->addonKey; |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Set clientKey |
||
| 204 | * |
||
| 205 | * @param string $clientKey |
||
| 206 | * |
||
| 207 | * @return TenantTrait|TenantInterface |
||
| 208 | */ |
||
| 209 | public function setClientKey(string $clientKey): TenantInterface |
||
| 210 | { |
||
| 211 | $this->clientKey = $clientKey; |
||
| 212 | |||
| 213 | return $this; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get clientKey |
||
| 218 | * |
||
| 219 | * @return string|null |
||
| 220 | */ |
||
| 221 | public function getClientKey(): ?string |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Set publicKey |
||
| 228 | * |
||
| 229 | * @param string $publicKey |
||
| 230 | * |
||
| 231 | * @return TenantTrait|TenantInterface |
||
| 232 | */ |
||
| 233 | public function setPublicKey(string $publicKey): TenantInterface |
||
| 234 | { |
||
| 235 | $this->publicKey = $publicKey; |
||
| 236 | |||
| 237 | return $this; |
||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Get publicKey |
||
| 242 | * |
||
| 243 | * @return string|null |
||
| 244 | */ |
||
| 245 | public function getPublicKey(): ?string |
||
| 246 | { |
||
| 247 | return $this->publicKey; |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Set sharedSecret |
||
| 252 | * |
||
| 253 | * @param string $sharedSecret |
||
| 254 | * |
||
| 255 | * @return TenantTrait|TenantInterface |
||
| 256 | */ |
||
| 257 | public function setSharedSecret(string $sharedSecret): TenantInterface |
||
| 258 | { |
||
| 259 | $this->sharedSecret = $sharedSecret; |
||
| 260 | |||
| 261 | return $this; |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Get sharedSecret |
||
| 266 | * |
||
| 267 | * @return string|null |
||
| 268 | */ |
||
| 269 | public function getSharedSecret(): ?string |
||
| 270 | { |
||
| 271 | return $this->sharedSecret; |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Set serverVersion |
||
| 276 | * |
||
| 277 | * @param string $serverVersion |
||
| 278 | * |
||
| 279 | * @return TenantTrait|TenantInterface |
||
| 280 | */ |
||
| 281 | public function setServerVersion(string $serverVersion): TenantInterface |
||
| 282 | { |
||
| 283 | $this->serverVersion = $serverVersion; |
||
| 284 | |||
| 285 | return $this; |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Get serverVersion |
||
| 290 | * |
||
| 291 | * @return string|null |
||
| 292 | */ |
||
| 293 | public function getServerVersion(): ?string |
||
| 294 | { |
||
| 295 | return $this->serverVersion; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Set pluginsVersion |
||
| 300 | * |
||
| 301 | * @param string $pluginsVersion |
||
| 302 | * |
||
| 303 | * @return TenantTrait|TenantInterface |
||
| 304 | */ |
||
| 305 | public function setPluginsVersion(string $pluginsVersion): TenantInterface |
||
| 306 | { |
||
| 307 | $this->pluginsVersion = $pluginsVersion; |
||
| 308 | |||
| 309 | return $this; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Get pluginsVersion |
||
| 314 | * |
||
| 315 | * @return string|null |
||
| 316 | */ |
||
| 317 | public function getPluginsVersion(): ?string |
||
| 318 | { |
||
| 319 | return $this->pluginsVersion; |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Set baseUrl |
||
| 324 | * |
||
| 325 | * @param string $baseUrl |
||
| 326 | * |
||
| 327 | * @return TenantTrait|TenantInterface |
||
| 328 | */ |
||
| 329 | public function setBaseUrl(string $baseUrl): TenantInterface |
||
| 330 | { |
||
| 331 | $this->baseUrl = $baseUrl; |
||
| 332 | |||
| 333 | return $this; |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Get baseUrl |
||
| 338 | * |
||
| 339 | * @return string|null |
||
| 340 | */ |
||
| 341 | public function getBaseUrl(): ?string |
||
| 342 | { |
||
| 343 | return $this->baseUrl; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Set productType |
||
| 348 | * |
||
| 349 | * @param string $productType |
||
| 350 | * |
||
| 351 | * @return TenantTrait|TenantInterface |
||
| 352 | */ |
||
| 353 | public function setProductType(string $productType): TenantInterface |
||
| 354 | { |
||
| 355 | $this->productType = $productType; |
||
| 356 | |||
| 357 | return $this; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Get productType |
||
| 362 | * |
||
| 363 | * @return string|null |
||
| 364 | */ |
||
| 365 | public function getProductType(): ?string |
||
| 366 | { |
||
| 367 | return $this->productType; |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Set description |
||
| 372 | * |
||
| 373 | * @param string $description |
||
| 374 | * |
||
| 375 | * @return TenantTrait|TenantInterface |
||
| 376 | */ |
||
| 377 | public function setDescription(string $description): TenantInterface |
||
| 378 | { |
||
| 379 | $this->description = $description; |
||
| 380 | |||
| 381 | return $this; |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Get description |
||
| 386 | * |
||
| 387 | * @return string|null |
||
| 388 | */ |
||
| 389 | public function getDescription(): ?string |
||
| 390 | { |
||
| 391 | return $this->description; |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Set eventType |
||
| 396 | * |
||
| 397 | * @param string $eventType |
||
| 398 | * |
||
| 399 | * @return TenantTrait|TenantInterface |
||
| 400 | */ |
||
| 401 | public function setEventType(string $eventType): TenantInterface |
||
| 402 | { |
||
| 403 | $this->eventType = $eventType; |
||
| 404 | |||
| 405 | return $this; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Get eventType |
||
| 410 | * |
||
| 411 | * @return string|null |
||
| 412 | */ |
||
| 413 | public function getEventType(): ?string |
||
| 414 | { |
||
| 415 | return $this->eventType; |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Implementing UserInterface |
||
| 420 | * |
||
| 421 | * @return string[] |
||
| 422 | */ |
||
| 423 | public function getRoles(): array |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return string |
||
| 430 | */ |
||
| 431 | public function getPassword(): string |
||
| 432 | { |
||
| 433 | return ''; |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @return string |
||
| 438 | */ |
||
| 439 | public function getSalt(): string |
||
| 440 | { |
||
| 441 | return ''; |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @return null|string |
||
| 446 | */ |
||
| 447 | public function getUsername(): ?string |
||
| 448 | { |
||
| 449 | return $this->username; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @param string $name |
||
| 454 | * |
||
| 455 | * @return TenantTrait|TenantInterface |
||
| 456 | */ |
||
| 457 | public function setUsername(string $name): TenantInterface |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return void |
||
| 466 | */ |
||
| 467 | public function eraseCredentials(): void |
||
| 468 | { |
||
| 469 | } |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @return bool |
||
| 473 | */ |
||
| 474 | public function getIsWhiteListed(): bool |
||
| 475 | { |
||
| 476 | return $this->isWhiteListed; |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * @param bool $isWhiteListed |
||
| 481 | * |
||
| 482 | * @return self |
||
| 483 | */ |
||
| 484 | public function setIsWhiteListed(bool $isWhiteListed): self |
||
| 485 | { |
||
| 486 | $this->isWhiteListed = $isWhiteListed; |
||
| 487 | |||
| 488 | return $this; |
||
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @return null|\DateTime |
||
| 493 | */ |
||
| 494 | public function getWhiteListedUntil(): ?\DateTime |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @param \DateTime $whiteListedUntil |
||
| 501 | * |
||
| 502 | * @return self |
||
| 503 | */ |
||
| 504 | public function setWhiteListedUntil(\DateTime $whiteListedUntil): self |
||
| 505 | { |
||
| 506 | $this->whiteListedUntil = $whiteListedUntil; |
||
| 507 | |||
| 508 | return $this; |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @return bool |
||
| 513 | */ |
||
| 514 | public function isWhiteListed(): bool |
||
| 515 | { |
||
| 516 | $now = new \DateTime(); |
||
| 517 | |||
| 518 | return $this->getIsWhiteListed() && ($this->getWhiteListedUntil() === null || ($now < $this->getWhiteListedUntil())); |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @param string|null $oauthClientId |
||
| 523 | * |
||
| 524 | * @return TenantInterface |
||
| 525 | */ |
||
| 526 | public function setOauthClientId(?string $oauthClientId): TenantInterface |
||
| 527 | { |
||
| 528 | $this->oauthClientId = $oauthClientId; |
||
| 529 | |||
| 530 | return $this; |
||
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @return string|null |
||
| 535 | */ |
||
| 536 | public function getOauthClientId(): ?string |
||
| 539 | } |
||
| 540 | } |
||
| 541 |