Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractClause
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
9 / 9
16
100.00% covered (success)
100.00%
1 / 1
 setTable
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 hasAlias
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAlias
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAlias
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setValues
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 addValue
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
6
 getValues
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getValue
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
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\Db\Sql;
16
17/**
18 * Abstract clause class
19 *
20 * @category   Pop
21 * @package    Pop\Db
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    7.0.0
26 */
27abstract class AbstractClause extends AbstractSql
28{
29
30    /**
31     * Table
32     * @var mixed
33     */
34    protected mixed $table = null;
35
36    /**
37     * Alias
38     * @var ?string
39     */
40    protected ?string $alias = null;
41
42    /**
43     * Values
44     * @var array
45     */
46    protected array $values = [];
47
48    /**
49     * Set the table
50     *
51     * @param  mixed $table
52     * @return AbstractClause
53     */
54    public function setTable(mixed $table): AbstractClause
55    {
56        $this->table = $table;
57        return $this;
58    }
59
60    /**
61     * Determine if there is an alias
62     *
63     * @return bool
64     */
65    public function hasAlias(): bool
66    {
67        return ($this->alias !== null);
68    }
69
70    /**
71     * Get the alias
72     *
73     * @return ?string
74     */
75    public function getAlias(): ?string
76    {
77        return $this->alias;
78    }
79
80    /**
81     * Set the alias
82     *
83     * @param  string $alias
84     * @return AbstractClause
85     */
86    public function setAlias(string $alias): AbstractClause
87    {
88        $this->alias = $alias;
89        return $this;
90    }
91
92    /**
93     * Get the table
94     *
95     * @return ?string
96     */
97    public function getTable(): ?string
98    {
99        return $this->table;
100    }
101
102    /**
103     * Set the values
104     *
105     * @param  array $values
106     * @return AbstractClause
107     */
108    public function setValues(array $values): AbstractClause
109    {
110        foreach ($values as $column => $value) {
111            if ($this->isParameter($value, $column)) {
112                $values[$column] = $this->getParameter($value, $column);
113            }
114        }
115
116        $this->values = $values;
117        return $this;
118    }
119
120    /**
121     * Add a value
122     *
123     * @param  mixed  $value
124     * @param  ?string $name
125     * @return AbstractClause
126     */
127    public function addValue(mixed $value, ?string $name = null): AbstractClause
128    {
129        if (!is_array($value) && (($value instanceof \Stringable) || !is_object($value))) {
130            if ($this->isParameter($value, $name)) {
131                $value = $this->getParameter($value, $name);
132            }
133            if ($name !== null) {
134                $this->values[$name] = $value;
135            } else {
136                $this->values[] = $value;
137            }
138        }
139        return $this;
140    }
141
142    /**
143     * Get the values
144     *
145     * @return array
146     */
147    public function getValues(): array
148    {
149        return $this->values;
150    }
151
152    /**
153     * Get a value
154     *
155     * @param  string $name
156     * @return mixed
157     */
158    public function getValue(string $name): mixed
159    {
160        return $this->values[$name] ?? null;
161    }
162
163    /**
164     * Render the statement
165     *
166     * @return string
167     */
168    abstract public function render(): string;
169
170}