Completed
Push — nln-php7 ( 311875...6680df )
by Nicolas
11:20
created

AbstractSectionParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 54
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Karma\Configuration\Parser;
6
7
abstract class AbstractSectionParser implements SectionParser
8
{
9
    private const
10
        COMMENT_CHARACTER = '#';
11
12
    protected ?string
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
13
        $currentFilePath;
14
15
    protected ?int
16
        $currentLineNumber;
17
18 280
    public function __construct()
19
    {
20 280
        $this->currentFilePath = null;
21 280
        $this->currentLineNumber = null;
22 280
    }
23
24 280
    public function setCurrentFile(string $filePath): void
25
    {
26 280
        $this->currentFilePath = $filePath;
27 280
    }
28
29 274
    protected function isACommentLine(string $line): bool
30
    {
31 274
        return strpos(trim($line), self::COMMENT_CHARACTER) === 0;
32
    }
33
34 274
    final public function parse(string $line, int $lineNumber): void
35
    {
36 274
        $this->currentLineNumber = $lineNumber;
37
38 274
        if($this->isACommentLine($line))
39
        {
40 211
            return;
41
        }
42
43 274
        $this->parseLine($line);
44 253
    }
45
46
    abstract protected function parseLine(string $line): void;
47
48 28
    protected function triggerError(string $message, string $title = 'Syntax error'): void
49
    {
50 28
        throw new \RuntimeException(sprintf(
51 28
            '%s in %s line %d : %s',
52
            $title,
53 28
            $this->currentFilePath,
54 28
            $this->currentLineNumber,
55
            $message
56
        ));
57
    }
58
59 247
    public function postParse(): void
60
    {
61 247
    }
62
}
63