Lines 100.00% 60 / 60
Methods 100.00% 16 / 16
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 sql 100.00% 8 / 8 100.00% 1 / 1 2
 valuesSQL 100.00% 10 / 10 100.00% 1 / 1 3
 params 100.00% 1 / 1 100.00% 1 / 1 1
 reset 100.00% 3 / 3 100.00% 1 / 1 1
 allTablesReferenced 100.00% 3 / 3 100.00% 1 / 1 2
 [BO\Zmsbackend\Query\Builder\TableName] table 100.00% 4 / 4 100.00% 1 / 1 2
 [BO\Zmsbackend\Query\Builder\Values] values 100.00% 4 / 4 100.00% 1 / 1 2
 [BO\Zmsbackend\Query\Builder\Values] value 100.00% 4 / 4 100.00% 1 / 1 3
 [BO\Zmsbackend\Query\Builder\Values] resetValues 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsbackend\Query\Builder\Query] __construct 100.00% 1 / 1 100.00% 1 / 1 2
 [BO\Zmsbackend\Query\Builder\Query] queryBaseStatement 100.00% 4 / 4 100.00% 1 / 1 2
 [BO\Zmsbackend\Query\Builder\Query] dialect 100.00% 4 / 4 100.00% 1 / 1 2
 [BO\Zmsbackend\Query\Builder\Query] flag 100.00% 4 / 4 100.00% 1 / 1 3
 [BO\Zmsbackend\Query\Builder\Query] flags 100.00% 5 / 5 100.00% 1 / 1 3
 [BO\Zmsbackend\Query\Builder\Query] deleteFlag 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsbackend\Query\Builder\Query] __toString 100.00% 1 / 1 100.00% 1 / 1 1
14class Insert extends Query
15{
16    use TableName;
17    use Values;
18
19    /**
20     * @var     string      The base part of the query
21     */
22    protected $queryBase = 'INSERT INTO';
23
24    /**
25     * Generates the full SQL statement for this query with all the composite parts.
26     *
27     * @return  string
28     */
29    #[\Override]
30    public function sql()
31    {
32        if ($this->table === null) {
33            return '';
34        }
35
36        $candidateParts = [
37            $this->queryBase,
38            $this->dialect->quoteTable($this->table),
39            $this->valuesSQL(),
40        ];
41
42        return implode(' ', $candidateParts);
43    }
44
45    /**
46     * Returns the values part of a query for an INSERT statement (so using VALUES())
47     *
48     * @return  string
49     */
50    protected function valuesSQL()
51    {
52        $sql = '';
53        if (!empty($this->values)) {
54            $keyParts = [];
55            $valueParts = [];
56            foreach (array_keys($this->values) as $field) {
57                $keyParts[]     = $this->dialect->quoteField($field);
58                $valueParts[]   = '?';
59            }
60
61            $sql .= '(' . implode(', ', $keyParts) . ') ';
62            $sql .= 'VALUES (' . implode(', ', $valueParts) . ')';
63        }
64        return $sql;
65    }
66
67    /**
68     * Returns all the parameters, in the correct order, to pass into PDO.
69     *
70     * @return  array
71     */
72    #[\Override]
73    public function params()
74    {
75        return array_values($this->values);
76    }
77
78    /**
79     * Resets the entire query.
80     *
81     * @return  $this
82     */
83    #[\Override]
84    public function reset()
85    {
86        $this->table = null;
87        $this->resetValues();
88        return $this;
89    }
90
91    /*
92     * ------------------- All Tables ------------------------
93     */
94
95    /**
96     * Returns all the tables that this query makes mention of, in FROMs and JOINs
97     *
98     * @return  array
99     */
100    #[\Override]
101    public function allTablesReferenced()
102    {
103        if ($this->table()) {
104            return [$this->table()];
105        }
106        return [];
107    }
108}

From BO\Zmsbackend\Query\Builder\TableName

14trait TableName
15{
16    /**
17     * @var     array     Table to update
18     */
19    protected $table = null;
20
21    /**
22     * Set/Get the table we're updating
23     *
24     * @param   string|null     $table      string to set, null to get
25     * @return  $this|string
26     */
27    public function table($table = null)
28    {
29        if ($table === null) {
30            return $this->table;
31        }
32        $this->table = $table;
33        return $this;
34    }
35}

From BO\Zmsbackend\Query\Builder\Values

14trait Values
15{
16    protected $values = [];
17
18    /**
19     * Sets / Gets an array of values for the update/insert query
20     *
21     * @param   array|null   $values
22     * @return  $this|array
23     */
24    public function values(?array $values = null)
25    {
26        if ($values === null) {
27            return $this->values;
28        }
29
30        $this->values = array_merge($this->values, $values);
31        return $this;
32    }
33
34    /**
35     * Sets/gets a single value for a given field
36     *
37     * @param   string          $field
38     * @param   mixed|null      $value
39     * @return  $this|mixed
40     */
41    public function value($field, $value = null)
42    {
43        if ($value === null) {
44            return (array_key_exists($field, $this->values)) ? $this->values[$field] : null;
45        }
46        $this->values[$field] = $value;
47        return $this;
48    }
49
50    /**
51     * Resets the values to a default state.
52     *
53     * @return  $this
54     */
55    public function resetValues()
56    {
57        $this->values = [];
58        return $this;
59    }
60}

Inherited from BO\Zmsbackend\Query\Builder\Query

42    public function __construct(?DialectInterface $dialect = null)
43    {
44        $this->dialect = ($dialect === null) ? new ANSI() : $dialect;
45    }
54    public function queryBaseStatement($base = null)
55    {
56        if ($base === null) {
57            return $this->queryBase;
58        }
59        $this->queryBase = $base;
60        return $this;
61    }
70    public function dialect(?DialectInterface $dialect = null)
71    {
72        if ($dialect === null) {
73            return $this->dialect;
74        }
75        $this->dialect = $dialect;
76        return $this;
77    }
92    public function flag($flag, $value = null)
93    {
94        if ($value === null) {
95            return (array_key_exists($flag, $this->flags)) ? $this->flags[$flag] : null;
96        }
97        $this->flags[$flag] = $value;
98        return $this;
99    }
110    public function flags(?array $flags = null)
111    {
112        if (!is_array($flags)) {
113            return $this->flags;
114        }
115        foreach ($flags as $f => $v) {
116            $this->flags[$f] = $v;
117        }
118        return $this;
119    }
128    public function deleteFlag($flag)
129    {
130        unset($this->flags[$flag]);
131        return $this;
132    }
146    public function __toString()
147    {
148        return $this->sql();
149    }