Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Statement
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 reset
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 sql
n/a
0 / 0
n/a
0 / 0
0
 run
n/a
0 / 0
n/a
0 / 0
0
1<?php declare(strict_types=1);
2/*
3 * This file is part of Aplus Framework Database Library.
4 *
5 * (c) Natan Felles <natanfelles@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10namespace Framework\Database;
11
12/**
13 * Class Statement.
14 *
15 * @package database
16 */
17abstract class Statement implements \Stringable
18{
19    protected Database $database;
20    /**
21     * SQL clauses and parts.
22     *
23     * @var array<string,mixed>
24     */
25    protected array $sql = [];
26
27    /**
28     * Statement constructor.
29     *
30     * @param Database $database
31     */
32    public function __construct(Database $database)
33    {
34        $this->database = $database;
35    }
36
37    public function __toString() : string
38    {
39        return $this->sql();
40    }
41
42    /**
43     * Resets SQL clauses and parts.
44     *
45     * @param string|null $sql A part name or null to reset all
46     *
47     * @see Statement::$sql
48     *
49     * @return static
50     */
51    public function reset(string $sql = null) : static
52    {
53        if ($sql === null) {
54            unset($this->sql);
55            return $this;
56        }
57        unset($this->sql[$sql]);
58        return $this;
59    }
60
61    /**
62     * Renders the SQL statement.
63     *
64     * @return string
65     */
66    abstract public function sql() : string;
67
68    /**
69     * Runs the SQL statement.
70     *
71     * @return mixed
72     */
73    abstract public function run() : mixed;
74}