Failed Conditions
Pull Request — master (#1109)
by Abdeali
02:35
created

bears.linters.PHPLintBear   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %
Metric Value
dl 0
loc 19
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _get_groupdict() 0 6 1
A run() 0 5 1
1
import re
2
3
from coalib.bearlib.abstractions.Lint import Lint
4
from coalib.bears.LocalBear import LocalBear
5
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
6
7
8
class PHPLintBear(LocalBear, Lint):
9
    executable = 'php'
10
    arguments = '-l -n -d display_errors=On -d log_errors=Off'
11
    output_regex = re.compile(
12
        r'(?P<severity>\S+) error: '
13
        r'(?P<message>.*) in (?P<file_name>.*) on line (?P<line>\d+)')
14
15
    def _get_groupdict(self, match):
16
        groups = Lint._get_groupdict(self, match)
17
        # As `php -l` only shows Fatal errorsor Parsing errors both are
18
        # considered as Major
19
        groups['severity'] = RESULT_SEVERITY.MAJOR
20
        return groups
21
22
    def run(self, filename, file):
23
        '''
24
        Checks the code with `php -l`. This runs it on each file separately.
25
        '''
26
        return self.lint(filename)
27