|
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 PHPCodeSniffer. |
|
10
|
|
|
* @see https://github.com/squizlabs/PHP_CodeSniffer |
|
11
|
|
|
*/ |
|
12
|
|
|
class PHPCodeSniffer extends AbstractIntegration |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getDescription() |
|
18
|
|
|
{ |
|
19
|
|
|
return 'PHPCodeSniffer'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getIgnoredArgument() |
|
26
|
|
|
{ |
|
27
|
|
|
if (!empty($this->ignoredPaths)) { |
|
28
|
|
|
return '--ignore=' . implode(',', $this->ignoredPaths) . ' '; |
|
29
|
|
|
} |
|
30
|
|
|
return ''; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @inheritdoc |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getCommand($targetPaths) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->binariesPath . 'phpcs -p --standard=PSR2 --report=xml ' |
|
39
|
|
|
. $this->getIgnoredArgument() . '--report-file="' |
|
40
|
|
|
. $this->temporaryFilePath . '" ' . implode(' ', $targetPaths); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function addIssuesFromXml(Reader $xml) |
|
47
|
|
|
{ |
|
48
|
|
|
$xmlArray = $xml->parse(); |
|
49
|
|
|
|
|
50
|
|
|
foreach ((array) $xmlArray['value'] as $fileTag) { |
|
51
|
|
|
if ($fileTag['name'] != '{}file') { |
|
52
|
|
|
continue; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$fileName = $fileTag['attributes']['name']; |
|
56
|
|
|
|
|
57
|
|
|
foreach ((array) $fileTag['value'] as $issueTag) { |
|
58
|
|
|
$line = $issueTag['attributes']['line']; |
|
59
|
|
|
$tool = 'PHPCodeSniffer'; |
|
60
|
|
|
$type = $issueTag['attributes']['source']; |
|
61
|
|
|
$message = $issueTag['value']; |
|
62
|
|
|
|
|
63
|
|
|
$this->result->addIssue($fileName, $line, $tool, $type, $message); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|