forked from spaceemotion/php-coding-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpMessDetector.php
More file actions
64 lines (48 loc) · 1.58 KB
/
PhpMessDetector.php
File metadata and controls
64 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Spaceemotion\PhpCodingStandard\Tools;
use Spaceemotion\PhpCodingStandard\Context;
use Spaceemotion\PhpCodingStandard\Formatter\File;
use Spaceemotion\PhpCodingStandard\Formatter\Result;
use Spaceemotion\PhpCodingStandard\Formatter\Violation;
class PhpMessDetector extends Tool
{
/** @var string */
protected $name = 'phpmd';
protected function supportsMemoryLimit(): bool
{
return true;
}
public function run(Context $context): bool
{
$output = [];
if (
$this->execute(self::vendorBinary($this->name), [
implode(',', $context->files),
'json',
'phpmd.xml',
], $output) === 0
) {
return true;
}
$json = self::parseJson(implode('', $output));
if ($json === []) {
return false;
}
$result = new Result();
foreach ($json['files'] as $entry) {
$file = new File();
foreach ($entry['violations'] as $details) {
$violation = new Violation();
$violation->line = (int) $details['beginLine'];
$violation->message = $details['description'];
$violation->source = "{$details['ruleSet']} > {$details['rule']} ({$details['externalInfoUrl']})";
$violation->tool = $this->name;
$file->violations[] = $violation;
}
$result->files[$entry['file']] = $file;
}
$context->addResult($result);
return false;
}
}