vanderlee /
Comprehend
| 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
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
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
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
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
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 |