| Conditions | 5 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | 16 | public function header($header, $replace = true) |
|
| 12 | { |
||
| 13 | 16 | if (preg_match("~^HTTP/~", $header) === 1) { |
|
| 14 | 15 | array_unshift($this->headerList, $header); |
|
| 15 | 15 | return; |
|
| 16 | } |
||
| 17 | |||
| 18 | 12 | if ($replace) { |
|
| 19 | 12 | $headerParts = explode(':', $header); |
|
| 20 | 12 | for ($i=0; $i<count($this->headerList); $i++) { |
|
|
|
|||
| 21 | 8 | if (preg_match("~^" . $headerParts[0] . "~", $this->headerList[$i]) === 1) { |
|
| 22 | 7 | $this->headerList[$i] = $header; |
|
| 23 | 7 | return; |
|
| 24 | } |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | 12 | $this->headerList[] = $header; |
|
| 29 | } |
||
| 49 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: