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