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