1
|
|
|
<?php |
2
|
|
|
namespace Finder\Logic\Tools; |
3
|
|
|
|
4
|
|
|
use Finder\Logic\AnalysisResult; |
5
|
|
|
use Support\Helps\ArrayHelper; |
6
|
|
|
use Sabre\Xml\Reader; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Integration of CodeAnalyser with CodeSniffer. |
10
|
|
|
* |
11
|
|
|
* @see https://github.com/squizlabs/PHP_CodeSniffer |
12
|
|
|
*/ |
13
|
|
|
class CodeSniffer extends AbstractTool |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @inheritdoc |
17
|
|
|
*/ |
18
|
|
|
public function getDescription() |
19
|
|
|
{ |
20
|
|
|
return 'CodeSniffer'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function getIgnoredArgument() |
27
|
|
|
{ |
28
|
|
|
if (!empty($this->ignoredPaths)) { |
29
|
|
|
return '--ignore=' . implode(',', $this->ignoredPaths) . ' '; |
30
|
|
|
} |
31
|
|
|
return ''; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
|
|
public function getCommand($targetPaths) |
38
|
|
|
{ |
39
|
|
|
return $this->binariesPath . 'phpcs -p --standard=PSR2 --report=xml ' |
40
|
|
|
. $this->getIgnoredArgument() . '--report-file="' |
41
|
|
|
. $this->temporaryFilePath . '" ' . implode(' ', $targetPaths); |
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']['line']; |
60
|
|
|
$tool = 'CodeSniffer'; |
61
|
|
|
$type = $issueTag['attributes']['source']; |
62
|
|
|
$message = $issueTag['value']; |
63
|
|
|
|
64
|
|
|
$this->result->addIssue($fileName, $line, $tool, $type, $message); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|