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 |
||
111 | private function checkHeaders(array $protected, array $headers) |
||
112 | { |
||
113 | $checkedHeaders = []; |
||
114 | foreach ($this->checkers as $header => $checker) { |
||
115 | if ($checker->protectedHeaderOnly()) { |
||
116 | if (array_key_exists($header, $protected)) { |
||
117 | $checker->checkHeader($protected[$header]); |
||
118 | $checkedHeaders[] = $header; |
||
119 | } else { |
||
120 | throw new \InvalidArgumentException(sprintf('The header "%s" must be protected.', $header)); |
||
121 | } |
||
122 | } else { |
||
123 | if (array_key_exists($header, $protected)) { |
||
124 | $checker->checkHeader($protected[$header]); |
||
125 | $checkedHeaders[] = $header; |
||
126 | } elseif (array_key_exists($header, $headers)) { |
||
127 | $checker->checkHeader($headers[$header]); |
||
128 | $checkedHeaders[] = $header; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | |||
133 | if (array_key_exists('crit', $protected)) { |
||
134 | if (!is_array($protected['crit'])) { |
||
135 | throw new \InvalidArgumentException('The header "crit" mus be a list of header parameters.'); |
||
136 | } |
||
137 | $diff = array_diff($protected['crit'], $checkedHeaders); |
||
138 | if (!empty($diff)) { |
||
139 | 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)))); |
||
140 | } |
||
141 | } elseif (array_key_exists('crit', $headers)) { |
||
142 | throw new \InvalidArgumentException('The header parameter "crit" must be protected.'); |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 |