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