| Conditions | 10 | 
| Paths | 26 | 
| Total Lines | 34 | 
| Code Lines | 24 | 
| 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 | ||
| 142 | private function checkHeaders(array $protected, array $headers) | ||
| 143 |     { | ||
| 144 | $checkedHeaders = []; | ||
| 145 |         foreach ($this->checkers as $header => $checker) { | ||
| 146 |             if ($checker->protectedHeaderOnly()) { | ||
| 147 |                 if (array_key_exists($header, $protected)) { | ||
| 148 | $checker->checkHeader($protected[$header]); | ||
| 149 | $checkedHeaders[] = $header; | ||
| 150 |                 } else { | ||
| 151 |                     throw new \InvalidArgumentException(sprintf('The header "%s" must be protected.', $header)); | ||
| 152 | } | ||
| 153 |             } else { | ||
| 154 |                 if (array_key_exists($header, $protected)) { | ||
| 155 | $checker->checkHeader($protected[$header]); | ||
| 156 | $checkedHeaders[] = $header; | ||
| 157 |                 } elseif (array_key_exists($header, $headers)) { | ||
| 158 | $checker->checkHeader($headers[$header]); | ||
| 159 | $checkedHeaders[] = $header; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 |         if (array_key_exists('crit', $protected)) { | ||
| 165 |             if (!is_array($protected['crit'])) { | ||
| 166 |                 throw new \InvalidArgumentException('The header "crit" mus be a list of header parameters.'); | ||
| 167 | } | ||
| 168 | $diff = array_diff($protected['crit'], $checkedHeaders); | ||
| 169 |             if (!empty($diff)) { | ||
| 170 |                 throw new \InvalidArgumentException(sprintf('One or more headers are marked as critical, but they are missing or have not been checked: %s.', implode(', ', array_values($diff)))); | ||
| 171 | } | ||
| 172 |         } elseif (array_key_exists('crit', $headers)) { | ||
| 173 |             throw new \InvalidArgumentException('The header parameter "crit" must be protected.'); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 |