| Conditions | 10 |
| Paths | 261 |
| Total Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 80 | private function syncCircle(Circle $circle, string $source): void { |
||
| 81 | try { |
||
| 82 | $knownCircle = $this->circlesRequest->forceGetCircle($circle->getUniqueId()); |
||
| 83 | |||
| 84 | if (!$this->compareCircles($knownCircle, $circle)) { |
||
| 85 | try { |
||
| 86 | $this->circlesRequest->updateCircle($circle); |
||
| 87 | } catch (CircleAlreadyExistsException $e) { |
||
|
|
|||
| 88 | } |
||
| 89 | } |
||
| 90 | } catch (CircleDoesNotExistException $e) { |
||
| 91 | try { |
||
| 92 | $this->circlesRequest->createCircle($circle); |
||
| 93 | } catch (CircleAlreadyExistsException $e) { |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | foreach ($circle->getMembers() as $member) { |
||
| 98 | if ($member->getInstance() === '') { |
||
| 99 | $member->setInstance($source); |
||
| 100 | } |
||
| 101 | |||
| 102 | try { |
||
| 103 | $knownMember = $this->membersRequest->forceGetMember( |
||
| 104 | $circle->getUniqueId(), $member->getUserId(), $member->getType(), $member->getInstance() |
||
| 105 | ); |
||
| 106 | |||
| 107 | if ($this->compareMembers($knownMember, $member)) { |
||
| 108 | continue; |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->miscService->log( |
||
| 112 | 'updating member :' . json_encode($member) . ' from ' . json_encode($knownMember), 2 |
||
| 113 | ); |
||
| 114 | $this->membersRequest->updateMember($member); |
||
| 115 | } catch (MemberDoesNotExistException $e) { |
||
| 116 | try { |
||
| 117 | $this->miscService->log( |
||
| 118 | 'creating member :' . json_encode($member), 2 |
||
| 119 | ); |
||
| 120 | $this->membersRequest->createMember($member); |
||
| 121 | } catch (MemberAlreadyExistsException $e) { |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | } |
||
| 127 | |||
| 166 |