Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractResult
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 toArray
n/a
0 / 0
n/a
0 / 0
0
 getConfidence
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isConfident
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 result 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 AbstractResult implements ResultInterface
28{
29
30    /**
31     * Confidence score (0.0-1.0) reflecting how much of the input was confidently matched
32     * against a recognized pattern vs. guessed/absorbed as leftover content. Defaults to 1.0
33     * (full confidence) - a concrete result's constructor sets it from whatever confidence
34     * value its parser computed, if any.
35     * @var float
36     */
37    protected float $confidence = 1.0;
38
39    /**
40     * To array method
41     *
42     * @return array
43     */
44    abstract public function toArray(): array;
45
46    /**
47     * Get confidence score
48     *
49     * @return float
50     */
51    public function getConfidence(): float
52    {
53        return $this->confidence;
54    }
55
56    /**
57     * Whether the confidence score meets or exceeds the given threshold
58     *
59     * @param  float $threshold
60     * @return bool
61     */
62    public function isConfident(float $threshold = 0.7): bool
63    {
64        return $this->confidence >= $threshold;
65    }
66
67}