Completed
Push — master ( c80620...0cd8d9 )
by Martijn
03:25
created

Match::__get()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 5
nop 1
dl 0
loc 14
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace Vanderlee\Comprehend\Match;
4
5
use Vanderlee\Comprehend\Core\Token;
6
7
/**
8
 * Description of ParserToken
9
 *
10
 * @author Martijn
11
 *
12
 * @property-read bool $match Success or failure?
13
 * @property-read int $length Length of the match
14
 * @property-read array $results List of output results
15
 * @property-read string|array|null $result Default output result
16
 * @property-read Token|null $token
17
 */
18
abstract class Match
19
{
20
21
    private $length;
22
23
    /**
24
     * @param string $name
25
     * @return mixed
26
     * @throws \Exception
27
     */
28
    public function __get($name)
29
    {
30
        switch ($name) {
31
            case 'length':
32
                return $this->length;
33
            case 'results':
34
                return [];
35
            case 'result':
36
                return null;
37
            case 'token':
38
                return null;
39
        }
40
41
        throw new \InvalidArgumentException("Property name `{$name}` not recognized");
42
    }
43
44
    /**
45
     * Create a new match
46
     *
47
     * @param int $length
48
     */
49
    public function __construct(int $length = 0)
50
    {
51
        $this->length = $length;
0 ignored issues
show
Bug introduced by
The property length is declared read-only in Vanderlee\Comprehend\Match\Match.
Loading history...
52
    }
53
54
    /**
55
     * Resolve any match stuff (should only ever be called from AbstractParser!
56
     * Not for human consumption
57
     *
58
     * @return $this
59
     */
60
    public function resolve()
61
    {
62
        return $this;
63
    }
64
65
    /**
66
     * Return the result for the name specified or the default value if not set.
67
     *
68
     * @param string|null $name
69
     * @param mixed $default
70
     * @return mixed
71
     */
72
    public function getResult($name = null, $default = null)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    public function getResult(/** @scrutinizer ignore-unused */ $name = null, $default = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
    {
74
        return $default;
75
    }
76
77
    /**
78
     * Return whether there is a result for the name specified.
79
     *
80
     * @param string|null $name
81
     * @return boolean
82
     */
83
    public function hasResult($name = null)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

83
    public function hasResult(/** @scrutinizer ignore-unused */ $name = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
    {
85
        return false;
86
    }
87
88
}
89