Completed
Branch master (06cb84)
by Tomáš
06:00
created

FileToTokensParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 43
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parseFromFilePath() 0 7 1
A parseLegacyWithFileContentAndEolChar() 0 4 1
A getLegacyConfig() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\PHP7_CodeSniffer\Parser;
9
10
use Nette\Utils\FileSystem;
11
use PHP_CodeSniffer\Tokenizers\PHP;
12
use stdClass;
13
14
final class FileToTokensParser
15
{
16
    /**
17
     * @var EolCharDetector
18
     */
19
    private $eolCharDetector;
20
21 1
    public function __construct(EolCharDetector $eolCharDetector)
22
    {
23 1
        $this->eolCharDetector = $eolCharDetector;
24 1
    }
25
26
    /**
27
     * @var stdClass
28
     */
29
    private $legacyConfig;
30
31 1
    public function parseFromFilePath(string $filePath) : array
32
    {
33 1
        $fileContent = FileSystem::read($filePath);
34 1
        $eolChar = $this->eolCharDetector->detectForContent($fileContent);
35
36 1
        return $this->parseLegacyWithFileContentAndEolChar($fileContent, $eolChar);
37
    }
38
39 1
    private function parseLegacyWithFileContentAndEolChar($fileContent, $eolChar) : array
40
    {
41 1
        return (new PHP($fileContent, $this->getLegacyConfig(), $eolChar))->getTokens();
42
    }
43
44 1
    private function getLegacyConfig() : stdClass
45
    {
46 1
        if ($this->legacyConfig) {
47
            return $this->legacyConfig;
48
        }
49
50 1
        $config = new stdClass();
51 1
        $config->tabWidth = 4;
52 1
        $this->legacyConfig = $config;
53
54 1
        return $this->legacyConfig;
55
    }
56
}
57