Complex classes like Client 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class Client extends BaseClient implements ClientInterface, ClaimProviderInterface |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @ORM\Id |
||
| 39 | * @ORM\Column(type="integer") |
||
| 40 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 41 | * @JMS\Expose |
||
| 42 | * @JMS\Groups({"public"}) |
||
| 43 | */ |
||
| 44 | protected $id; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @ORM\Column(type="string", nullable=false, unique=true) |
||
| 48 | * @JMS\Expose |
||
| 49 | * @JMS\SerializedName("client_name") |
||
| 50 | * @JMS\Groups({"public", "remote_claim"}) |
||
| 51 | */ |
||
| 52 | protected $name; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @ORM\Column(type="string", length=4000, nullable=true) |
||
| 56 | * @JMS\Expose |
||
| 57 | * @JMS\Groups({"public"}) |
||
| 58 | */ |
||
| 59 | protected $description; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @ORM\Column(type="string", length=2000, nullable=true) |
||
| 63 | * @JMS\Expose |
||
| 64 | * @JMS\Groups({"public"}) |
||
| 65 | */ |
||
| 66 | protected $landingPageUrl; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @ORM\Column(type="string", length=2000, nullable=true) |
||
| 70 | * @JMS\Expose |
||
| 71 | * @JMS\Groups({"public"}) |
||
| 72 | */ |
||
| 73 | protected $termsOfUseUrl; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @ORM\Column(type="json_array", nullable=false) |
||
| 77 | */ |
||
| 78 | protected $allowedScopes; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @ORM\OneToMany(targetEntity="LoginCidadao\CoreBundle\Entity\Authorization", mappedBy="client", cascade={"remove"}, orphanRemoval=true) |
||
| 82 | * @var Authorization[] |
||
| 83 | */ |
||
| 84 | protected $authorizations; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @ORM\Column(type="string", length=2000, nullable=true) |
||
| 88 | * @JMS\Expose |
||
| 89 | * @JMS\Groups({"public"}) |
||
| 90 | */ |
||
| 91 | protected $siteUrl; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @Assert\File( |
||
| 95 | * maxSize="2M", |
||
| 96 | * maxSizeMessage="The maxmimum allowed file size is 2MB.", |
||
| 97 | * mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}, |
||
| 98 | * mimeTypesMessage="Only JPEG and PNG images are allowed." |
||
| 99 | * ) |
||
| 100 | * @Vich\UploadableField(mapping="client_image", fileNameProperty="imageName") |
||
| 101 | * @var File $image |
||
| 102 | * @JMS\Since("1.0.2") |
||
| 103 | */ |
||
| 104 | protected $image; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @ORM\Column(type="string", length=255, name="image_name", nullable=true) |
||
| 108 | * |
||
| 109 | * @var string $imageName |
||
| 110 | * @JMS\Since("1.0.2") |
||
| 111 | */ |
||
| 112 | protected $imageName; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @ORM\Column(type="boolean", nullable=false) |
||
| 116 | * @JMS\Expose |
||
| 117 | * @JMS\Groups({"public"}) |
||
| 118 | */ |
||
| 119 | protected $published; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @ORM\Column(type="boolean", nullable=false) |
||
| 123 | * @JMS\Expose |
||
| 124 | * @JMS\Groups({"public"}) |
||
| 125 | */ |
||
| 126 | protected $visible; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @ORM\ManyToMany(targetEntity="LoginCidadao\CoreBundle\Entity\Person", inversedBy="clients" ) |
||
| 130 | * @ORM\JoinTable(name="client_owners", |
||
| 131 | * joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")}, |
||
| 132 | * inverseJoinColumns={@ORM\JoinColumn(name="client_id", referencedColumnName="id")} |
||
| 133 | * ) |
||
| 134 | * @var PersonInterface[] |
||
| 135 | */ |
||
| 136 | protected $owners; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @ORM\OneToMany(targetEntity="LoginCidadao\APIBundle\Entity\LogoutKey", mappedBy="client") |
||
| 140 | */ |
||
| 141 | protected $logoutKeys; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var \LoginCidadao\OpenIDBundle\Entity\ClientMetadata |
||
| 145 | * @ORM\OneToOne(targetEntity="LoginCidadao\OpenIDBundle\Entity\ClientMetadata", mappedBy="client", cascade={"persist"}) |
||
| 146 | */ |
||
| 147 | protected $metadata; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @ORM\Column(name="updated_at", type="datetime") |
||
| 151 | */ |
||
| 152 | protected $updatedAt; |
||
| 153 | /** |
||
| 154 | * @ORM\Column(type="string", nullable=true, unique=true) |
||
| 155 | * @var string |
||
| 156 | */ |
||
| 157 | private $uid; |
||
| 158 | 35 | ||
| 159 | public function __construct() |
||
| 170 | 1 | ||
| 171 | public static function getAllGrants() |
||
| 182 | 8 | ||
| 183 | /** |
||
| 184 | 8 | * @return string |
|
| 185 | 2 | */ |
|
| 186 | 2 | public function getName() |
|
| 200 | 1 | ||
| 201 | public function setName($name) |
||
| 210 | |||
| 211 | public function getDescription() |
||
| 215 | |||
| 216 | 2 | public function setDescription($description) |
|
| 222 | 1 | ||
| 223 | public function getSiteUrl() |
||
| 231 | 1 | ||
| 232 | public function setSiteUrl($url) |
||
| 241 | |||
| 242 | 2 | /** |
|
| 243 | * @param array|Authorization[] $authorizations |
||
| 244 | 2 | * @return $this |
|
| 245 | */ |
||
| 246 | 2 | public function setAuthorizations($authorizations = []) |
|
| 252 | 2 | ||
| 253 | /** |
||
| 254 | 2 | * @return array|Authorization[] |
|
| 255 | */ |
||
| 256 | public function getAuthorizations() |
||
| 260 | 2 | ||
| 261 | /** |
||
| 262 | 2 | * @param Authorization $authorization |
|
| 263 | 2 | */ |
|
| 264 | 2 | public function removeAuthorization(Authorization $authorization) |
|
| 272 | 1 | ||
| 273 | public function getLandingPageUrl() |
||
| 281 | 1 | ||
| 282 | public function setLandingPageUrl($landingPageUrl) |
||
| 291 | 1 | ||
| 292 | public function getTermsOfUseUrl() |
||
| 300 | 1 | ||
| 301 | public function setTermsOfUseUrl($termsOfUseUrl) |
||
| 310 | |||
| 311 | 2 | public function getAllowedScopes() |
|
| 321 | |||
| 322 | 7 | public function setAllowedScopes(array $allowedScopes) |
|
| 328 | |||
| 329 | public function isVisible() |
||
| 333 | |||
| 334 | 2 | public function setVisible($visible) |
|
| 340 | |||
| 341 | public function isPublished() |
||
| 345 | |||
| 346 | 2 | public function setPublished($published) |
|
| 352 | |||
| 353 | 7 | public function setId($var) |
|
| 359 | |||
| 360 | public function getOwners() |
||
| 364 | |||
| 365 | 2 | /* Unique Interface Stuff */ |
|
| 366 | |||
| 367 | 2 | public function setOwners($owners) |
|
| 373 | |||
| 374 | 1 | /** |
|
| 375 | * Gets the Unique Id of the Entity. |
||
| 376 | 1 | * @return string the entity UID |
|
| 377 | */ |
||
| 378 | public function getUid() |
||
| 382 | |||
| 383 | /** |
||
| 384 | 1 | * Sets the Unique Id of the Entity. |
|
| 385 | * @param string $uid the entity UID |
||
| 386 | 1 | * @return $this |
|
| 387 | */ |
||
| 388 | 1 | public function setUid($uid = null) |
|
| 394 | 1 | ||
| 395 | /** |
||
| 396 | 1 | * Compatibility with OIDC code |
|
| 397 | */ |
||
| 398 | public function getClientId() |
||
| 402 | 4 | ||
| 403 | /** |
||
| 404 | 4 | * Compatibility with OIDC code |
|
| 405 | */ |
||
| 406 | public function getClientSecret() |
||
| 410 | |||
| 411 | public function getMetadata() |
||
| 415 | |||
| 416 | 3 | public function setMetadata(ClientMetadata $metadata) |
|
| 422 | 1 | ||
| 423 | /** |
||
| 424 | * @JMS\VirtualProperty() |
||
| 425 | 11 | * @JMS\SerializedName("redirect_uris") |
|
| 426 | * @JMS\Groups({"remote_claim"}) |
||
| 427 | * @return array|string[] |
||
| 428 | 19 | */ |
|
| 429 | public function getRedirectUris() |
||
| 437 | |||
| 438 | public function setRedirectUris(array $redirectUris) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @return File |
||
| 451 | */ |
||
| 452 | public function getImage() |
||
| 456 | |||
| 457 | 1 | /** |
|
| 458 | * If manually uploading a file (i.e. not using Symfony Form) ensure an instance |
||
| 459 | 1 | * of 'UploadedFile' is injected into this setter to trigger the update. If this |
|
| 460 | * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter |
||
| 461 | 1 | * must be able to accept an instance of 'File' as the bundle will inject one here |
|
| 462 | 1 | * during Doctrine hydration. |
|
| 463 | * |
||
| 464 | * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image |
||
| 465 | 1 | * @return $this |
|
| 466 | */ |
||
| 467 | public function setImage($image) |
||
| 477 | |||
| 478 | /** |
||
| 479 | * @return string |
||
| 480 | 1 | */ |
|
| 481 | public function getImageName() |
||
| 485 | |||
| 486 | /** |
||
| 487 | 1 | * @param string $imageName |
|
| 488 | * @return $this |
||
| 489 | 1 | */ |
|
| 490 | public function setImageName($imageName) |
||
| 496 | |||
| 497 | public function getUpdatedAt() |
||
| 501 | 1 | ||
| 502 | /** |
||
| 503 | 2 | * @ORM\PrePersist |
|
| 504 | * @ORM\PreUpdate |
||
| 505 | * @param \DateTime|null $updatedAt |
||
| 506 | 2 | * @return $this |
|
| 507 | */ |
||
| 508 | public function setUpdatedAt($updatedAt = null) |
||
| 518 | 3 | ||
| 519 | /** |
||
| 520 | * {@inheritdoc} |
||
| 521 | 1 | */ |
|
| 522 | public function getAllowedGrantTypes() |
||
| 530 | 1 | ||
| 531 | public function ownsDomain($domain) |
||
| 542 | 1 | ||
| 543 | 1 | public function getContacts() |
|
| 556 | |||
| 557 | /** |
||
| 558 | * @JMS\VirtualProperty() |
||
| 559 | * @JMS\SerializedName("client_id") |
||
| 560 | * @JMS\Groups({"remote_claim"}) |
||
| 561 | * @inheritDoc |
||
| 562 | */ |
||
| 563 | public function getPublicId() |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @JMS\VirtualProperty() |
||
| 570 | * @JMS\SerializedName("client_uri") |
||
| 571 | * @JMS\Groups({"remote_claim"}) |
||
| 572 | */ |
||
| 573 | public function getClientUri() |
||
| 577 | } |
||
| 578 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.