Total Complexity | 6 |
Total Lines | 38 |
Duplicated Lines | 42.11 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class HeaderList extends HeadList |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Initializing the headers container. |
||
20 | */ |
||
21 | 3 | View Code Duplication | protected function initList() |
|
|||
22 | { |
||
23 | 3 | $headerList = array(); |
|
24 | 3 | foreach (explode("\r\n", trim($this->getInitData())) as $headerLine) { |
|
25 | 3 | if (empty($headerLine)) { |
|
26 | 1 | $headerList = array(); |
|
27 | 1 | continue; |
|
28 | } |
||
29 | 3 | if ($this->isHeaderHTTP($headerLine) || $this->isHeaderSetCookie($headerLine)) { |
|
30 | 1 | continue; |
|
31 | } |
||
32 | 3 | $headerParams = $this->getHeaderParams($headerLine); |
|
33 | 3 | $headerList[strtolower($headerParams['name'])] = new Header($headerParams); |
|
34 | } |
||
35 | 3 | $this->setList($headerList); |
|
36 | 3 | } |
|
37 | |||
38 | /** |
||
39 | * Splits Cookie HTTP header on the parameters. |
||
40 | * |
||
41 | * @param string $headerLine HTTP header line. |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | 3 | private function getHeaderParams($headerLine) |
|
53 | ); |
||
54 | } |
||
56 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.