CaseSensitive   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 38
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 7 1
A __toString() 0 5 2
A __construct() 0 4 1
1
<?php
2
3
namespace Vanderlee\Comprehend\Directive;
4
5
use Vanderlee\Comprehend\Core\ArgumentsTrait;
6
use Vanderlee\Comprehend\Core\Context;
7
use Vanderlee\Comprehend\Parser\Parser;
8
9
/**
10
 * Description of CaseDirective.
11
 *
12
 * @author Martijn
13
 */
14
class CaseSensitive extends Parser
15
{
16
    use ArgumentsTrait;
17
18
    /**
19
     * @var Parser
20
     */
21
    private $parser;
22
23
    /**
24
     * @var bool
25
     */
26
    private $sensitivity;
27
28
    /**
29
     * @param Parser|string|int $parser
30
     * @param bool $sensitivity
31
     */
32 1
    public function __construct($sensitivity, $parser)
33
    {
34 1
        $this->parser = self::getArgument($parser);
35 1
        $this->sensitivity = (bool)$sensitivity;
36 1
    }
37
38 5
    protected function parse(&$input, $offset, Context $context)
39
    {
40 5
        $context->pushCaseSensitivity($this->sensitivity);
41 5
        $match = $this->parser->parse($input, $offset, $context);
42 5
        $context->popCaseSensitivity();
43
44 5
        return $match;
45
    }
46
47 5
    public function __toString()
48
    {
49 5
        return ($this->sensitivity
50 2
                ? 'case'
51 5
                : 'no-case') . '( ' . $this->parser . ' )';
52
    }
53
}
54