Conditions | 3 |
Paths | 3 |
Total Lines | 19 |
Code Lines | 9 |
Lines | 19 |
Ratio | 100 % |
Changes | 0 |
1 | <?php declare(strict_types = 1); |
||
16 | View Code Duplication | public function parseViolations() : array |
|
|
|||
17 | { |
||
18 | |||
19 | // Read XML and convert to array |
||
20 | $xmlData = simplexml_load_string(file_get_contents($this->path)); |
||
21 | |||
22 | /** @var array $violations Collection of violations grouped by files and lines */ |
||
23 | $violations = []; |
||
24 | |||
25 | foreach ($xmlData->file as $file) { |
||
26 | $filePath = (string)$file[self::FILEPATH]; |
||
27 | $pointer = &$violations[ltrim(substr($filePath, strpos($filePath, $this->basePath)), '/')]; |
||
28 | foreach ($file->violation as $violation) { |
||
29 | $pointer[(string)$violation[self::LINENUMBER]][] = trim((string)$violation); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | return $violations; |
||
34 | } |
||
35 | } |
||
36 |
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.