Completed
Push — master ( 9667e2...b50d22 )
by X
24s
created

OptionalSignParser::isSign()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * parser for optional sign
5
 */
6
namespace xKerman\Restricted;
7
8
/**
9
 * Parser for optional sign
10
 */
11
class OptionalSignParser implements ParserInterface
12
{
13
    /**
14
     * parse given `$source` and return sign if exist
15
     *
16
     * @param Source $source parser input
17
     * @return array
18
     */
19 28
    public function parse(Source $source)
20
    {
21 28
        if (!$this->isSign($source->peek())) {
22 21
            return ['', $source];
23
        }
24 11
        $sign = $source->peek();
25 11
        $source->next();
26 11
        return [$sign, $source];
27
    }
28
29
    /**
30
     * judge if given `$char` is minus|plus sign
31
     *
32
     * @param string $char target character
33
     * @return boolean
34
     */
35 28
    private function isSign($char)
36
    {
37 28
        return $char === '+' || $char === '-';
38
    }
39
}
40