| 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 |
||
| 133 | private function checkHeaders(array $protected, array $headers) |
||
| 134 | { |
||
| 135 | $checkedHeaders = []; |
||
| 136 | foreach ($this->checkers as $header => $checker) { |
||
| 137 | if ($checker->protectedHeaderOnly()) { |
||
| 138 | if (array_key_exists($header, $protected)) { |
||
| 139 | $checker->checkHeader($protected[$header]); |
||
| 140 | $checkedHeaders[] = $header; |
||
| 141 | } else { |
||
| 142 | throw new \InvalidArgumentException(sprintf('The header "%s" must be protected.', $header)); |
||
| 143 | } |
||
| 144 | } else { |
||
| 145 | if (array_key_exists($header, $protected)) { |
||
| 146 | $checker->checkHeader($protected[$header]); |
||
| 147 | $checkedHeaders[] = $header; |
||
| 148 | } elseif (array_key_exists($header, $headers)) { |
||
| 149 | $checker->checkHeader($headers[$header]); |
||
| 150 | $checkedHeaders[] = $header; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | if (array_key_exists('crit', $protected)) { |
||
| 156 | if (!is_array($protected['crit'])) { |
||
| 157 | throw new \InvalidArgumentException('The header "crit" mus be a list of header parameters.'); |
||
| 158 | } |
||
| 159 | $diff = array_diff($protected['crit'], $checkedHeaders); |
||
| 160 | if (!empty($diff)) { |
||
| 161 | 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)))); |
||
| 162 | } |
||
| 163 | } elseif (array_key_exists('crit', $headers)) { |
||
| 164 | throw new \InvalidArgumentException('The header parameter "crit" must be protected.'); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } |
||
| 168 |