Completed
Push — 57-formatter-per-extension ( 73b3c8 )
by Nicolas
40:17 queued 36:16
created

AbstractSectionParser::setCurrentFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Karma\Configuration\Parser;
4
5
abstract class AbstractSectionParser implements SectionParser
6
{
7
    const
8
        COMMENT_CHARACTER = '#';
9
    
10
    protected
11
        $currentFilePath,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
12
        $currentLineNumber;
13
    
14
    public function __construct()
15
    {
16
        $this->currentFilePath = null;
17
        $this->currentLineNumber = null;
18
    }
19
    
20
    public function setCurrentFile($filePath)
21
    {
22
        $this->currentFilePath = $filePath;
23
    }
24
    
25
    protected function isACommentLine($line)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
26
    {
27
        return strpos(trim($line), self::COMMENT_CHARACTER) === 0;
28
    }
29
    
30
    final public function parse($line, $lineNumber)
31
    {
32
        $this->currentLineNumber = $lineNumber;
33
        
34
        return $this->parseLine($line);
35
    }
36
    
37
    abstract protected function parseLine($line);
38
    
39
    protected function triggerError($message, $title = 'Syntax error')
40
    {
41
        throw new \RuntimeException(sprintf(
42
            '%s in %s line %d : %s',
43
            $title,
44
            $this->currentFilePath,
45
            $this->currentLineNumber,
46
            $message
47
        ));
48
    }
49
    
50
    public function postParse()
51
    {
52
    }
53
}