| Conditions | 5 |
| Paths | 5 |
| Total Lines | 53 |
| Code Lines | 32 |
| 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 |
||
| 105 | public function enforceObligatoryLoa(Loa $originalRequiredLoa, $subjectId, $idpEntityId, $spEntityId, array $attributes, $clientIp) |
||
| 106 | { |
||
| 107 | $policyDecision = $this->client->requestDecisionFor( |
||
| 108 | Request::from($this->clientId, $subjectId, $idpEntityId, $spEntityId, $attributes, $clientIp) |
||
| 109 | ); |
||
| 110 | |||
| 111 | if (!$policyDecision->permitsAccess()) { |
||
| 112 | throw new RuntimeException( |
||
| 113 | sprintf( |
||
| 114 | 'The policy decision point (PDP) denied access (%s)', |
||
| 115 | $policyDecision->getFormattedStatus() |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | $newRequiredLoa = $originalRequiredLoa; |
||
| 121 | |||
| 122 | if ($policyDecision->hasLoaObligations()) { |
||
| 123 | $loaRequiredByPolicyDecision = $this->findHighestObligatoryLoa( |
||
| 124 | $policyDecision->getLoaObligations() |
||
| 125 | ); |
||
| 126 | |||
| 127 | if ($loaRequiredByPolicyDecision->equals($originalRequiredLoa)) { |
||
| 128 | $this->logger->info( |
||
| 129 | sprintf( |
||
| 130 | 'The policy decision point (PDP) sent an obligation for LoA %s, which matches the LoA already required.', |
||
| 131 | $loaRequiredByPolicyDecision |
||
| 132 | ) |
||
| 133 | ); |
||
| 134 | } elseif ($loaRequiredByPolicyDecision->canSatisfyLoa($originalRequiredLoa)) { |
||
| 135 | $newRequiredLoa = $loaRequiredByPolicyDecision; |
||
| 136 | |||
| 137 | $this->logger->info( |
||
| 138 | sprintf( |
||
| 139 | 'The policy decision point (PDP) sent an obligation for LoA %s, updating required LoA from %s to %s.', |
||
| 140 | $loaRequiredByPolicyDecision, |
||
| 141 | $originalRequiredLoa, |
||
| 142 | $loaRequiredByPolicyDecision |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | } else { |
||
| 146 | $this->logger->info( |
||
| 147 | sprintf( |
||
| 148 | 'The policy decision point (PDP) sent an obligation for LoA %s, but required LoA %s is higher - PDP has no effect.', |
||
| 149 | $loaRequiredByPolicyDecision, |
||
| 150 | $originalRequiredLoa |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | return $newRequiredLoa; |
||
| 157 | } |
||
| 158 | |||
| 186 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.