| Total Complexity | 47 |
| Total Lines | 236 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like IdentityServiceImpl 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 IdentityServiceImpl, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 67 | class IdentityServiceImpl extends ServiceImpl implements IdentityServiceInterface |
||
| 68 | { |
||
| 69 | /** thread local holding the current authentication */ |
||
| 70 | private $currentAuthentication; |
||
| 71 | |||
| 72 | public function isReadOnly(): bool |
||
| 73 | { |
||
| 74 | return $this->commandExecutor->execute(new IsIdentityServiceReadOnlyCmd()); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function newGroup(string $groupId): GroupInterface |
||
| 78 | { |
||
| 79 | return $this->commandExecutor->execute(new CreateGroupCmd($groupId)); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function newUser(string $userId): UserInterface |
||
| 83 | { |
||
| 84 | return $this->commandExecutor->execute(new CreateUserCmd($userId)); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function newTenant(string $tenantId): TenantInterface |
||
| 88 | { |
||
| 89 | return $this->commandExecutor->execute(new CreateTenantCmd($tenantId)); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function saveGroup(GroupInterface $group): void |
||
| 93 | { |
||
| 94 | try { |
||
| 95 | $this->commandExecutor->execute(new SaveGroupCmd($group)); |
||
| 96 | } catch (\Exception $ex) { |
||
| 97 | if (ExceptionUtil::checkConstraintViolationException($ex)) { |
||
| 98 | throw new BadUserRequestException("The group already exists", $ex); |
||
| 99 | } |
||
| 100 | throw $ex; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | public function saveUser(UserInterface $user, bool $skipPasswordPolicy = false): void |
||
| 105 | { |
||
| 106 | try { |
||
| 107 | $this->commandExecutor->execute(new SaveUserCmd($user, $skipPasswordPolicy)); |
||
| 108 | } catch (\Exception $ex) { |
||
| 109 | if (ExceptionUtil::checkConstraintViolationException($ex)) { |
||
| 110 | throw new BadUserRequestException("The user already exists", $ex); |
||
| 111 | } |
||
| 112 | throw $ex; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | public function saveTenant(TenantInterface $tenant): void |
||
| 117 | { |
||
| 118 | try { |
||
| 119 | $this->commandExecutor->execute(new SaveTenantCmd($tenant)); |
||
| 120 | } catch (\Exception $ex) { |
||
| 121 | if (ExceptionUtil::checkConstraintViolationException($ex)) { |
||
| 122 | throw new BadUserRequestException("The tenant already exists", $ex); |
||
| 123 | } |
||
| 124 | throw $ex; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | public function createUserQuery(): UserQueryInterface |
||
| 129 | { |
||
| 130 | return $this->commandExecutor->execute(new CreateUserQueryCmd()); |
||
| 131 | } |
||
| 132 | |||
| 133 | public function createNativeUserQuery(): NativeUserQueryInterface |
||
| 134 | { |
||
| 135 | return $this->commandExecutor->execute(new CreateNativeUserQueryCmd()); |
||
| 136 | } |
||
| 137 | |||
| 138 | public function createGroupQuery(): GroupQueryInterface |
||
| 141 | } |
||
| 142 | |||
| 143 | public function createTenantQuery(): TenantQueryInterface |
||
| 144 | { |
||
| 145 | return $this->commandExecutor->execute(new CreateTenantQueryCmd()); |
||
| 146 | } |
||
| 147 | |||
| 148 | public function createMembership(string $userId, string $groupId): void |
||
| 149 | { |
||
| 150 | $this->commandExecutor->execute(new CreateMembershipCmd($userId, $groupId)); |
||
| 151 | } |
||
| 152 | |||
| 153 | public function deleteGroup(string $groupId): void |
||
| 154 | { |
||
| 155 | $this->commandExecutor->execute(new DeleteGroupCmd($groupId)); |
||
| 156 | } |
||
| 157 | |||
| 158 | public function deleteMembership(string $userId, string $groupId): void |
||
| 159 | { |
||
| 160 | $this->commandExecutor->execute(new DeleteMembershipCmd($userId, $groupId)); |
||
| 161 | } |
||
| 162 | |||
| 163 | public function checkPassword(string $userId, string $password): bool |
||
| 164 | { |
||
| 165 | return $this->commandExecutor->execute(new CheckPassword($userId, $password)); |
||
| 166 | } |
||
| 167 | |||
| 168 | public function checkPasswordAgainstPolicy( |
||
| 169 | ?PasswordPolicyResultInterface $policy, |
||
| 170 | string $candidatePassword, |
||
| 171 | ?UserInterface $user |
||
| 172 | ): PasswordPolicyResultInterface { |
||
| 173 | $policy = $policy ?? $this->getPasswordPolicy(); |
||
| 174 | EnsureUtil::ensureNotNull("policy", "policy", $policy); |
||
| 175 | EnsureUtil::ensureNotNull("password", "candidatePassword", $candidatePassword); |
||
| 176 | |||
| 177 | $violatedRules = []; |
||
| 178 | $fulfilledRules = []; |
||
| 179 | |||
| 180 | foreach ($policy->getRules() as $rule) { |
||
|
|
|||
| 181 | if ($rule->execute($candidatePassword, $user)) { |
||
| 182 | $fulfilledRules[] = $rule; |
||
| 183 | } else { |
||
| 184 | $violatedRules[] = $rule; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | return new PasswordPolicyResultImpl($violatedRules, $fulfilledRules); |
||
| 188 | } |
||
| 189 | |||
| 190 | public function getPasswordPolicy(): PasswordPolicyInterface |
||
| 191 | { |
||
| 192 | return $this->commandExecutor->execute(new GetPasswordPolicyCmd()); |
||
| 193 | } |
||
| 194 | |||
| 195 | public function unlockUser(string $userId): void |
||
| 196 | { |
||
| 197 | $this->commandExecutor->execute(new UnlockUserCmd($userId)); |
||
| 198 | } |
||
| 199 | |||
| 200 | public function deleteUser(string $userId): void |
||
| 201 | { |
||
| 202 | $this->commandExecutor->execute(new DeleteUserCmd($userId)); |
||
| 203 | } |
||
| 204 | |||
| 205 | public function deleteTenant(string $tenantId): void |
||
| 206 | { |
||
| 207 | $this->commandExecutor->execute(new DeleteTenantCmd($tenantId)); |
||
| 208 | } |
||
| 209 | |||
| 210 | public function setUserPicture(string $userId, Picture $picture): void |
||
| 211 | { |
||
| 212 | $this->commandExecutor->execute(new SetUserPictureCmd($userId, $picture)); |
||
| 213 | } |
||
| 214 | |||
| 215 | public function getUserPicture(string $userId): Picture |
||
| 216 | { |
||
| 217 | return $this->commandExecutor->execute(new GetUserPictureCmd($userId)); |
||
| 218 | } |
||
| 219 | |||
| 220 | public function deleteUserPicture(string $userId): void |
||
| 221 | { |
||
| 222 | $this->commandExecutor->execute(new DeleteUserPictureCmd($userId)); |
||
| 223 | } |
||
| 224 | |||
| 225 | public function setAuthenticatedUserId(string $authenticatedUserId): void |
||
| 226 | { |
||
| 227 | $this->setAuthentication(new Authentication($authenticatedUserId, null)); |
||
| 228 | } |
||
| 229 | |||
| 230 | public function setAuthentication(string $userId, array $groups, ?array $tenantIds = null): void |
||
| 231 | { |
||
| 232 | $this->currentAuthentication = new Authentication($userId, $groups, $tenantIds); |
||
| 233 | } |
||
| 234 | |||
| 235 | public function clearAuthentication(): void |
||
| 236 | { |
||
| 237 | $this->currentAuthentication = null; |
||
| 238 | } |
||
| 239 | |||
| 240 | public function getCurrentAuthentication(): ?Authentication |
||
| 241 | { |
||
| 242 | return $this->currentAuthentication; |
||
| 243 | } |
||
| 244 | |||
| 245 | public function getUserInfo(string $userId, string $key): string |
||
| 248 | } |
||
| 249 | |||
| 250 | public function getUserInfoKeys(string $userId): array |
||
| 251 | { |
||
| 252 | return $this->commandExecutor->execute(new GetUserInfoKeysCmd($userId, IdentityInfoEntity::TYPE_USERINFO)); |
||
| 253 | } |
||
| 254 | |||
| 255 | public function getUserAccountNames(string $userId): array |
||
| 256 | { |
||
| 257 | return $this->commandExecutor->execute(new GetUserInfoKeysCmd($userId, IdentityInfoEntity::TYPE_USERACCOUNT)); |
||
| 258 | } |
||
| 259 | |||
| 260 | public function setUserInfo(string $userId, string $key, string $value): void |
||
| 263 | } |
||
| 264 | |||
| 265 | public function deleteUserInfo(string $userId, string $key): void |
||
| 266 | { |
||
| 267 | $this->commandExecutor->execute(new DeleteUserInfoCmd($userId, $key)); |
||
| 268 | } |
||
| 269 | |||
| 270 | public function deleteUserAccount(string $userId, string $accountName): void |
||
| 271 | { |
||
| 272 | $this->commandExecutor->execute(new DeleteUserInfoCmd($userId, $accountName)); |
||
| 273 | } |
||
| 274 | |||
| 275 | public function getUserAccount(string $userId, string $userPassword, string $accountName): ?AccountInterface |
||
| 276 | { |
||
| 277 | return $this->commandExecutor->execute(new GetUserAccountCmd($userId, $userPassword, $accountName)); |
||
| 278 | } |
||
| 279 | |||
| 280 | public function setUserAccount(string $userId, string $userPassword, string $accountName, string $accountUsername, string $accountPassword, array $accountDetails): void |
||
| 281 | { |
||
| 282 | $this->commandExecutor->execute(new SetUserInfoCmd($userId, $userPassword, $accountName, $accountUsername, $accountPassword, $accountDetails)); |
||
| 283 | } |
||
| 284 | |||
| 285 | public function createTenantUserMembership(string $tenantId, string $userId): void |
||
| 286 | { |
||
| 287 | $this->commandExecutor->execute(new CreateTenantUserMembershipCmd($tenantId, $userId)); |
||
| 288 | } |
||
| 289 | |||
| 290 | public function createTenantGroupMembership(string $tenantId, string $groupId): void |
||
| 291 | { |
||
| 292 | $this->commandExecutor->execute(new CreateTenantGroupMembershipCmd($tenantId, $groupId)); |
||
| 293 | } |
||
| 294 | |||
| 295 | public function deleteTenantUserMembership(string $tenantId, string $userId): void |
||
| 296 | { |
||
| 297 | $this->commandExecutor->execute(new DeleteTenantUserMembershipCmd($tenantId, $userId)); |
||
| 298 | } |
||
| 299 | |||
| 300 | public function deleteTenantGroupMembership(string $tenantId, string $groupId): void |
||
| 303 | } |
||
| 304 | } |
||
| 305 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.