Linter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 26
c 0
b 0
f 0
dl 0
loc 64
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A lint() 0 49 5
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;
0 ignored issues
show
introduced by
The private property $configuration is not used, and could be removed.
Loading history...
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