Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractPredicate
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFormat
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setValues
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getValues
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setConjunction
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 getConjunction
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 render
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Db\Sql\Predicate;
15
16use Pop\Db\Sql\AbstractSql;
17
18/**
19 * Abstract predicate class
20 *
21 * @category   Pop
22 * @package    Pop\Db
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    6.5.0
27 */
28abstract class AbstractPredicate
29{
30
31    /**
32     * Format
33     * @var ?string
34     */
35    protected ?string $format = null;
36
37    /**
38     * Values
39     * @var mixed
40     */
41    protected mixed $values = null;
42
43    /**
44     * Conjunction
45     * @var string
46     */
47    protected string $conjunction = 'AND';
48
49    /**
50     * Constructor
51     *
52     * Instantiate the predicate set object
53     *
54     * @param  mixed  $values
55     * @param  string $conjunction
56     * @throws Exception
57     */
58    public function __construct(mixed $values, string $conjunction = 'AND')
59    {
60        $this->setValues($values);
61        $this->setConjunction($conjunction);
62    }
63
64    /**
65     * Get the format
66     *
67     * @return string
68     */
69    public function getFormat(): string
70    {
71        return $this->format;
72    }
73
74    /**
75     * Set values
76     *
77     * @param  mixed  $values
78     * @return AbstractPredicate
79     */
80    public function setValues(mixed $values): AbstractPredicate
81    {
82        $this->values = $values;
83        return $this;
84    }
85
86    /**
87     * Get the values
88     *
89     * @return mixed
90     */
91    public function getValues(): mixed
92    {
93        return $this->values;
94    }
95
96    /**
97     * Get the conjunction
98     *
99     * @param  string $conjunction
100     * @throws Exception
101     * @return AbstractPredicate
102     */
103    public function setConjunction(string $conjunction): AbstractPredicate
104    {
105        if ((strtoupper($conjunction) != 'OR') && (strtoupper($conjunction) != 'AND')) {
106            throw new Exception("Error: The conjunction must be 'AND' or 'OR'. '" . $conjunction . "' is not allowed.");
107        }
108
109        $this->conjunction = $conjunction;
110
111        return $this;
112    }
113
114    /**
115     * Get the conjunction
116     *
117     * @return string
118     */
119    public function getConjunction(): string
120    {
121        return $this->conjunction;
122    }
123
124    /**
125     * Render the predicate string
126     *
127     * @param  AbstractSql $sql
128     * @return string
129     */
130    abstract public function render(AbstractSql $sql): string;
131
132}