@@ 12-72 (lines=61) @@ | ||
9 | * Integration of PHPHound with PHPCopyPasteDetector. |
|
10 | * @see https://github.com/sebastianbergmann/phpcpd |
|
11 | */ |
|
12 | class PHPCopyPasteDetector extends AbstractIntegration |
|
13 | { |
|
14 | /** |
|
15 | * @inheritdoc |
|
16 | */ |
|
17 | public function getDescription() |
|
18 | { |
|
19 | return 'PHPCopyPasteDetector'; |
|
20 | } |
|
21 | ||
22 | /** |
|
23 | * @inheritdoc |
|
24 | */ |
|
25 | public function getIgnoredArgument() |
|
26 | { |
|
27 | if (!empty($this->ignoredPaths)) { |
|
28 | return '--exclude={' . implode(',', $this->ignoredPaths) . '} '; |
|
29 | } |
|
30 | return ''; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * @inheritdoc |
|
35 | */ |
|
36 | public function getCommand($targetPaths) |
|
37 | { |
|
38 | return $this->binariesPath . 'phpcpd ' |
|
39 | . implode(' ', $targetPaths) . ' ' |
|
40 | . $this->getIgnoredArgument() . '--log-pmd="' |
|
41 | . $this->temporaryFilePath . '"'; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @inheritdoc |
|
46 | */ |
|
47 | protected function addIssuesFromXml(Reader $xml) |
|
48 | { |
|
49 | $xmlArray = $xml->parse(); |
|
50 | ||
51 | foreach ((array) $xmlArray['value'] as $duplicationTag) { |
|
52 | if ($duplicationTag['name'] != '{}duplication' |
|
53 | || empty($duplicationTag['value'])) { |
|
54 | continue; |
|
55 | } |
|
56 | ||
57 | foreach ((array) $duplicationTag['value'] as $fileTag) { |
|
58 | if ($fileTag['name'] != '{}file') { |
|
59 | continue; |
|
60 | } |
|
61 | ||
62 | $fileName = $fileTag['attributes']['path']; |
|
63 | $line = $fileTag['attributes']['line']; |
|
64 | $tool = 'PHPCopyPasteDetector'; |
|
65 | $type = 'duplication'; |
|
66 | $message = 'Duplicated code'; |
|
67 | ||
68 | $this->result->addIssue($fileName, $line, $tool, $type, $message); |
|
69 | } |
|
70 | } |
|
71 | } |
|
72 | } |
|
73 |
@@ 12-68 (lines=57) @@ | ||
9 | * Integration of PHPHound with PHPMessDetector. |
|
10 | * @see https://github.com/phpmd/phpmd |
|
11 | */ |
|
12 | class PHPMessDetector extends AbstractIntegration |
|
13 | { |
|
14 | /** |
|
15 | * @inheritdoc |
|
16 | */ |
|
17 | public function getDescription() |
|
18 | { |
|
19 | return 'PHPMessDetector'; |
|
20 | } |
|
21 | ||
22 | /** |
|
23 | * @inheritdoc |
|
24 | */ |
|
25 | public function getIgnoredArgument() |
|
26 | { |
|
27 | if (!empty($this->ignoredPaths)) { |
|
28 | return '--exclude ' . implode(',', $this->ignoredPaths) . ' '; |
|
29 | } |
|
30 | return ''; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * @inheritdoc |
|
35 | */ |
|
36 | public function getCommand($targetPaths) |
|
37 | { |
|
38 | return $this->binariesPath . 'phpmd ' . implode(',', $targetPaths) . ' ' |
|
39 | . 'xml cleancode,codesize,controversial,design,naming,unusedcode ' |
|
40 | . $this->getIgnoredArgument() . '> "' |
|
41 | . $this->temporaryFilePath . '"'; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @inheritdoc |
|
46 | */ |
|
47 | protected function addIssuesFromXml(Reader $xml) |
|
48 | { |
|
49 | $xmlArray = $xml->parse(); |
|
50 | ||
51 | foreach ((array) $xmlArray['value'] as $fileTag) { |
|
52 | if ($fileTag['name'] != '{}file') { |
|
53 | continue; |
|
54 | } |
|
55 | ||
56 | $fileName = $fileTag['attributes']['name']; |
|
57 | ||
58 | foreach ((array) $fileTag['value'] as $issueTag) { |
|
59 | $line = $issueTag['attributes']['beginline']; |
|
60 | $tool = 'PHPMessDetector'; |
|
61 | $type = $issueTag['attributes']['rule']; |
|
62 | $message = $issueTag['value']; |
|
63 | ||
64 | $this->result->addIssue($fileName, $line, $tool, $type, $message); |
|
65 | } |
|
66 | } |
|
67 | } |
|
68 | } |
|
69 |