1
|
|
|
<?php |
2
|
|
|
namespace phphound\integration; |
3
|
|
|
|
4
|
|
|
use phphound\AnalysisResult; |
5
|
|
|
use phphound\helper\ArrayHelper; |
6
|
|
|
use Sabre\Xml\Reader; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Integration of PHPHound with PHPMessDetector. |
10
|
|
|
* @see https://github.com/phpmd/phpmd |
11
|
|
|
*/ |
12
|
|
View Code Duplication |
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
|
|
|
|
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.