AbstractMatch   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 70
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

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

75
    public function getResult(/** @scrutinizer ignore-unused */ string $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...
76
    {
77 3
        return $default;
78
    }
79
80
    /**
81
     * Return whether there is a result for the name specified.
82
     *
83
     * @param string|null $name
84
     *
85
     * @return bool
86
     */
87 3
    public function hasResult(string $name = null): bool
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

87
    public function hasResult(/** @scrutinizer ignore-unused */ string $name = null): bool

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...
88
    {
89 3
        return false;
90
    }
91
}
92