Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractParser
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
1 / 1
 parse
n/a
0 / 0
n/a
0 / 0
0
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getData
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setData
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getResult
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getErrorMessage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Parser;
16
17/**
18 * Abstract parser class
19 *
20 * @category   Pop
21 * @package    Pop\Parser
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    1.0.0
26 */
27abstract class AbstractParser implements ParserInterface
28{
29
30    /**
31     * Data to parse
32     * @var mixed
33     */
34    protected mixed $data = null;
35
36    /**
37     * Error flag
38     * @var bool
39     */
40    protected bool $error = false;
41
42    /**
43     * Error message
44     * @var ?string
45     */
46    protected ?string $errorMessage = null;
47
48    /**
49     * Parsed result
50     * @var mixed
51     */
52    protected mixed $result = null;
53
54    /**
55     * Parse method
56     *
57     * @return static
58     */
59    abstract public function parse(): static;
60
61    /**
62     * Constructor
63     *
64     * Instantiate the parse object
65     *
66     * @param  mixed $data
67     */
68    public function __construct(mixed $data = null)
69    {
70        if (null !== $data) {
71            $this->setData($data);
72        }
73    }
74
75    /**
76     * Get data
77     *
78     * @return mixed
79     */
80    public function getData(): mixed
81    {
82        return $this->data;
83    }
84
85    /**
86     * Set data
87     *
88     * @param  mixed $data
89     * @return static
90     */
91    public function setData(mixed $data): static
92    {
93        $this->data = $data;
94        return $this;
95    }
96
97    /**
98     * Get parsed result
99     *
100     * @return mixed
101     */
102    public function getResult(): mixed
103    {
104        return $this->result;
105    }
106
107    /**
108     * Check if there is an error
109     *
110     * @return bool
111     */
112    public function hasError(): bool
113    {
114        return $this->error;
115    }
116
117    /**
118     * Get error message
119     *
120     * @return ?string
121     */
122    public function getErrorMessage(): ?string
123    {
124        return $this->errorMessage;
125    }
126
127}