|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Pluswerk\TypoScriptAutoFixer\Adapter; |
|
5
|
|
|
|
|
6
|
|
|
use Exception; |
|
7
|
|
|
use Helmich\TypoScriptLint\Linter\Report\File; |
|
8
|
|
|
use Helmich\TypoScriptLint\Linter\Sniff\SniffLocator; |
|
9
|
|
|
use Helmich\TypoScriptParser\Parser\Parser; |
|
10
|
|
|
use Helmich\TypoScriptParser\Tokenizer\Tokenizer; |
|
11
|
|
|
use Pluswerk\TypoScriptAutoFixer\Adapter\Configuration\Configuration; |
|
12
|
|
|
use Pluswerk\TypoScriptAutoFixer\Issue\AbstractIssue; |
|
13
|
|
|
use Pluswerk\TypoScriptAutoFixer\Issue\IssueCollection; |
|
14
|
|
|
|
|
15
|
|
|
class Linter |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Configuration |
|
19
|
|
|
*/ |
|
20
|
|
|
private $configuration; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $filePath |
|
24
|
|
|
* |
|
25
|
|
|
* @return IssueCollection |
|
26
|
|
|
* @throws Exception |
|
27
|
|
|
* |
|
28
|
|
|
* @todo REFACTOR - just copy paste ;) |
|
29
|
|
|
*/ |
|
30
|
|
|
public function lint(string $filePath): IssueCollection |
|
31
|
|
|
{ |
|
32
|
|
|
$configuration = Configuration::getInstance()->getLinterConfiguration(); |
|
33
|
|
|
|
|
34
|
|
|
$sniffLocator = new SniffLocator(); |
|
35
|
|
|
|
|
36
|
|
|
$tokenizer = new Tokenizer(); |
|
37
|
|
|
$parser = new Parser($tokenizer); |
|
38
|
|
|
|
|
39
|
|
|
$file = new File($filePath); |
|
40
|
|
|
|
|
41
|
|
|
$tokens = $tokenizer->tokenizeStream($filePath); |
|
42
|
|
|
$statements = $parser->parseTokens($tokens); |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$sniffs = $sniffLocator->getTokenStreamSniffs($configuration); |
|
47
|
|
|
|
|
48
|
|
|
foreach ($sniffs as $sniff) { |
|
49
|
|
|
$sniffReport = $file->cloneEmpty(); |
|
50
|
|
|
|
|
51
|
|
|
$sniff->sniff($tokens, $sniffReport, $configuration); |
|
52
|
|
|
|
|
53
|
|
|
$file = $file->merge($sniffReport); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$sniffs = $sniffLocator->getSyntaxTreeSniffs($configuration); |
|
59
|
|
|
|
|
60
|
|
|
foreach ($sniffs as $sniff) { |
|
61
|
|
|
$sniffReport = $file->cloneEmpty(); |
|
62
|
|
|
|
|
63
|
|
|
$sniff->sniff($statements, $sniffReport, $configuration); |
|
64
|
|
|
|
|
65
|
|
|
$file = $file->merge($sniffReport); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$issueCollection = new IssueCollection(); |
|
69
|
|
|
$issueFactory = new IssueFactory(); |
|
70
|
|
|
|
|
71
|
|
|
foreach ($file->getIssues() as $issue) { |
|
72
|
|
|
$newIssue = $issueFactory->getIssue($issue, $tokens); |
|
73
|
|
|
if ($newIssue instanceof AbstractIssue) { |
|
74
|
|
|
$issueCollection->add($newIssue); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $issueCollection; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|