GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Optional::scan()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
ccs 13
cts 13
cp 1
crap 2
1
<?php
2
namespace GetSky\ParserExpressions\Rules;
3
4
use GetSky\ParserExpressions\Context;
5
use GetSky\ParserExpressions\Result;
6
use GetSky\ParserExpressions\RuleInterface;
7
8
/**
9
 * The optional operators consume zero or one consecutive
10
 * repetitions of their sub-expression e.
11
 *
12
 * @package GetSky\ParserExpressions\Rules
13
 * @author  Alexander Getmanskii <[email protected]>
14
 */
15
class Optional extends AbstractRule
16
{
17
18
    /**
19
     * @var \GetSky\ParserExpressions\RuleInterface
20
     */
21
    protected $rule;
22
23
    /**
24
     * @param array|string|RuleInterface $rule
25
     * @param string $name
26
     * @param callable $action
27
     */
28 1
    public function __construct($rule, $name = "Optional", callable $action = null)
29
    {
30 1
        $this->rule = $this->toRule($rule);
31 1
        $this->name = (string) $name;
32 1
        $this->action = $action;
33 1
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function scan(Context $context)
39
    {
40
41 1
        $index = $context->getCursor();
42
43 1
        $context->increaseDepth();
44 1
        $value = $this->rule->scan($context);
45 1
        $context->decreaseDepth();
46
47 1
        if (is_bool($value)) {
48 1
            $context->setCursor($index);
49 1
            return true;
50
        }
51
52 1
        $result = new Result($this->name);
53 1
        $result->setValue($value->getValue(), $index);
54 1
        $result->addChild($value);
55 1
        $this->action($result);
56
57 1
        return $result;
58
    }
59
}
60