Complex classes like FederatedEventService 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 FederatedEventService, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 78 | class FederatedEventService extends NC21Signature { | ||
| 79 | |||
| 80 | |||
| 81 | use TNC21Request; | ||
| 82 | use TStringTools; | ||
| 83 | |||
| 84 | /** @var IL10N */ | ||
| 85 | private $l10n; | ||
| 86 | |||
| 87 | /** @var RemoteWrapperRequest */ | ||
| 88 | private $remoteWrapperRequest; | ||
| 89 | |||
| 90 | /** @var RemoteRequest */ | ||
| 91 | private $remoteRequest; | ||
| 92 | |||
| 93 | /** @var RemoteUpstreamService */ | ||
| 94 | private $remoteUpstreamService; | ||
| 95 | |||
| 96 | /** @var ConfigService */ | ||
| 97 | private $configService; | ||
| 98 | |||
| 99 | /** @var MiscService */ | ||
| 100 | private $miscService; | ||
| 101 | |||
| 102 | |||
| 103 | /** | ||
| 104 | * FederatedEventService constructor. | ||
| 105 | * | ||
| 106 | * @param IL10N $l10n | ||
| 107 | * @param RemoteWrapperRequest $remoteWrapperRequest | ||
| 108 | * @param RemoteRequest $remoteRequest | ||
| 109 | * @param RemoteUpstreamService $remoteUpstreamService | ||
| 110 | * @param ConfigService $configService | ||
| 111 | */ | ||
| 112 | public function __construct( | ||
| 122 | |||
| 123 | |||
| 124 | /** | ||
| 125 | * Called when creating a new Event. | ||
| 126 | * This method will manage the event locally and upstream the payload if needed. | ||
| 127 | * | ||
| 128 | * @param FederatedEvent $event | ||
| 129 | * | ||
| 130 | * @throws InitiatorNotConfirmedException | ||
| 131 | * @throws OwnerNotFoundException | ||
| 132 | * @throws FederatedEventException | ||
| 133 | * @throws RequestNetworkException | ||
| 134 | * @throws RemoteNotFoundException | ||
| 135 | * @throws RemoteResourceNotFoundException | ||
| 136 | * @throws UnknownRemoteException | ||
| 137 | * @throws SignatoryException | ||
| 138 | * @throws FederatedItemException | ||
| 139 | * @throws FederatedEventDSyncException | ||
| 140 | */ | ||
| 141 | 	public function newEvent(FederatedEvent $event): void { | ||
| 175 | |||
| 176 | |||
| 177 | /** | ||
| 178 | * This confirmation is optional, method is just here to avoid going too far away on the process | ||
| 179 | * | ||
| 180 | * @param FederatedEvent $event | ||
| 181 | * @param bool $local | ||
| 182 | * | ||
| 183 | * @throws InitiatorNotConfirmedException | ||
| 184 | */ | ||
| 185 | 	public function confirmInitiator(FederatedEvent $event, bool $local = false): void { | ||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | // /** | ||
| 213 | // * We check that the event can be managed/checked locally or if the owner of the circle belongs to | ||
| 214 | // * an other instance of Nextcloud | ||
| 215 | // * | ||
| 216 | // * @param RemoteEvent $event | ||
| 217 | // * | ||
| 218 | // * @return bool | ||
| 219 | // * @throws CircleNotFoundException | ||
| 220 | // * @throws OwnerNotFoundException | ||
| 221 | // */ | ||
| 222 | //	public function isLocalEvent(RemoteEvent $event): bool { | ||
| 223 | ////		if ($event->isLocal()) { | ||
| 224 | //// return true; | ||
| 225 | //// } | ||
| 226 | // | ||
| 227 | // $circle = $event->getCircle(); | ||
| 228 | // | ||
| 229 | ////		if (!$circle->hasOwner()) { | ||
| 230 | // return ($this->configService->isLocalInstance($circle->getInstance())); | ||
| 231 | //// } | ||
| 232 | // | ||
| 233 | ////		if ($event->isVerifiedCircle()) { | ||
| 234 | //// $localCircle = $event->getCircle(); | ||
| 235 | ////		} else { | ||
| 236 | //// $localCircle = $this->circleRequest->getCircle($circle->getId()); | ||
| 237 | //// } | ||
| 238 | //// | ||
| 239 | //// $owner = $localCircle->getOwner(); | ||
| 240 | //// if ($owner->getInstance() === '' | ||
| 241 | ////			|| $this->configService->isLocalInstance($owner->getInstance())) { | ||
| 242 | //// return true; | ||
| 243 | //// } | ||
| 244 | //// | ||
| 245 | //// return false; | ||
| 246 | // } | ||
| 247 | |||
| 248 | |||
| 249 | /** | ||
| 250 | * @param FederatedEvent $event | ||
| 251 | * @param bool $checkLocalOnly | ||
| 252 | * | ||
| 253 | * @return IFederatedItem | ||
| 254 | * @throws FederatedEventException | ||
| 255 | */ | ||
| 256 | 	public function getFederatedItem(FederatedEvent $event, bool $checkLocalOnly = true): IFederatedItem { | ||
| 279 | |||
| 280 | |||
| 281 | /** | ||
| 282 | * Some event might need to bypass some checks | ||
| 283 | * | ||
| 284 | * @param FederatedEvent $event | ||
| 285 | * @param IFederatedItem $gs | ||
| 286 | */ | ||
| 287 | 	private function setFederatedEventBypass(FederatedEvent $event, IFederatedItem $gs) { | ||
| 298 | |||
| 299 | /** | ||
| 300 | * Some event might require additional check | ||
| 301 | * | ||
| 302 | * @param FederatedEvent $event | ||
| 303 | * @param IFederatedItem $item | ||
| 304 | * @param bool $checkLocalOnly | ||
| 305 | * | ||
| 306 | * @throws FederatedEventException | ||
| 307 | */ | ||
| 308 | private function confirmRequiredCondition( | ||
| 334 | |||
| 335 | |||
| 336 | /** | ||
| 337 | * @param FederatedEvent $event | ||
| 338 | * @param IFederatedItem $item | ||
| 339 | */ | ||
| 340 | 	private function configureEvent(FederatedEvent $event, IFederatedItem $item) { | ||
| 345 | |||
| 346 | |||
| 347 | /** | ||
| 348 | * async the process, generate a local request that will be closed. | ||
| 349 | * | ||
| 350 | * @param FederatedEvent $event | ||
| 351 | * @param array $filter | ||
| 352 | */ | ||
| 353 | 	public function initBroadcast(FederatedEvent $event, array $filter = []): void { | ||
| 383 | |||
| 384 | |||
| 385 | /** | ||
| 386 | * @param bool $all | ||
| 387 | * @param Circle|null $circle | ||
| 388 | * | ||
| 389 | * @return array | ||
| 390 | */ | ||
| 391 | 	public function getInstances(bool $all = false, ?Circle $circle = null): array { | ||
| 410 | |||
| 411 | |||
| 412 | /** | ||
| 413 | * @param array $current | ||
| 414 | */ | ||
| 415 | 	private function updateGlobalScaleInstances(array $current): void { | ||
| 418 | |||
| 419 | /** | ||
| 420 | * @return array | ||
| 421 | */ | ||
| 422 | 	private function getRemoteInstances(): array { | ||
| 425 | |||
| 426 | |||
| 427 | /** | ||
| 428 | * should be used to manage results from events, like sending mails on user creation | ||
| 429 | * | ||
| 430 | * @param string $token | ||
| 431 | */ | ||
| 432 | 	public function manageResults(string $token): void { | ||
| 459 | |||
| 460 | } | ||
| 461 | |||
| 462 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.