Completed
Push — master ( 2fd8e1...1442eb )
by Tomáš
03:40
created

FileToTokensParser::getLegacyConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 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 17
    public function __construct(EolCharDetector $eolCharDetector)
22
    {
23 17
        $this->eolCharDetector = $eolCharDetector;
24 17
    }
25
26
    /**
27
     * @var stdClass
28
     */
29
    private $legacyConfig;
30
31 15
    public function parseFromFilePath(string $filePath) : array
32
    {
33 15
        $fileContent = FileSystem::read($filePath);
34 15
        $eolChar = $this->eolCharDetector->detectForContent($fileContent);
35
36 15
        return $this->parseLegacyWithFileContentAndEolChar($fileContent, $eolChar);
37
    }
38
39 15
    private function parseLegacyWithFileContentAndEolChar(
40
        string $fileContent,
41
        string $eolChar
42
    ) : array {
43 15
        return (new PHP($fileContent, $this->getLegacyConfig(), $eolChar))->getTokens();
44
    }
45
46 15
    private function getLegacyConfig() : stdClass
47
    {
48 15
        if ($this->legacyConfig) {
49 1
            return $this->legacyConfig;
50
        }
51
52 15
        $config = new stdClass();
53 15
        $config->tabWidth = 4;
54 15
        $this->legacyConfig = $config;
55
56 15
        return $this->legacyConfig;
57
    }
58
}
59