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

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}

From BO\Zmsbackend\Query\Builder\Where

30trait Where
31{
32    /**
33     * @var     ConditionBuilder
34     */
35    protected $whereBuilder;
36
37    /**
38     * Get/Set an "AND WHERE" clause on the query. You can either pass a simple
39     * comparison ('name', '=', 'Alex') or a function to append multiple queries
40     * in a group.
41     *
42     * @param   string|\Closure|null    $field      Fieldname|callback for group|to return
43     * @param   string|null             $operator   Operator (=, !=, <>, <= etc)
44     * @param   mixed|null              $value      Value to test against
45     * @return  $this|array                         $this on set, array on get
46     */
47    public function where($field = null, $operator = null, $value = null)
48    {
49        if (!isset($this->whereBuilder)) {
50            $this->whereBuilder = new ConditionBuilder();
51        }
52        if ($field == null) {
53            return $this->whereBuilder->conditions();
54        }
55        $this->whereBuilder->andWith($field, $operator, $value);
56        return $this;
57    }
58
59    /**
60     * Adds a new 'OR ' predicate to the query.
61     *
62     * @param   string|\Closure|null    $field      Fieldname|callback for group|to return
63     * @param   string|null             $operator   Operator (=, !=, <>, <= etc)
64     * @param   mixed|null              $value      Value to test against
65     * @return  $this|array                         $this on set, array on get
66     * @psalm-api
67     */
68    public function orWhere($field = null, $operator = null, $value = null)
69    {
70        if (!isset($this->whereBuilder)) {
71            $this->whereBuilder = new ConditionBuilder();
72        }
73        if ($field == null) {
74            return $this->whereBuilder->conditions();
75        }
76        $this->whereBuilder->orWith($field, $operator, $value);
77        return $this;
78    }
79
80    /**
81     * @psalm-api
82     */
83    public function whereIn(string $field, array $values): static|array
84    {
85        if (empty($values)) {
86            throw new \InvalidArgumentException('whereIn() requires a non-empty $values array.');
87        }
88        return $this->where($field, 'IN', array_values($values));
89    }
90
91    /**
92     * Returns the SQL string for the WHERE portion of the query
93     *
94     * @param   DialectInterface    $dialect
95     * @return  string
96     */
97    public function buildWhereSQL(DialectInterface $dialect)
98    {
99        if (!isset($this->whereBuilder) || !$this->whereBuilder->hasConditions()) {
100            return '';
101        }
102
103        return 'WHERE ' . $this->whereBuilder->buildConditionSQL($dialect);
104    }
105
106    /**
107     * Returns an array of all the parameter that have been passed to where()
108     * ready to be thrown at PDO.
109     *
110     * @return  array
111     */
112    public function getWhereParams()
113    {
114        return (isset($this->whereBuilder)) ? $this->whereBuilder->getConditionParameters() : [];
115    }
116
117    /**
118     * Resets the WHERE portion of this query to empty.
119     *
120     * @return  $this
121     */
122    public function resetWhere()
123    {
124        unset($this->whereBuilder);
125        $this->whereBuilder = new ConditionBuilder();
126        return $this;
127    }
128}

From BO\Zmsbackend\Query\Builder\Paginate

15trait Paginate
16{
17    /**
18     * @var     int     Limit or results per page
19     */
20    protected $limit = null;
21
22    /**
23     * @var     int     Offset
24     */
25    protected $offset = 0;
26
27    /**
28     * Set/Get the limit of the query
29     *
30     * @param   int|null    $limit  Int to set, null to get
31     * @return  $this|int
32     */
33    public function limit($limit = null)
34    {
35        if ($limit === null) {
36            return $this->limit;
37        }
38
39        $this->limit = (int)$limit;
40        return $this;
41    }
42
43    /**
44     * Set/Get the offset of the query
45     *
46     * @param   int|null    $offset     Int to set, null to get
47     * @return  $this|int
48     */
49    public function offset($offset = null)
50    {
51        if ($offset === null) {
52            return $this->offset;
53        }
54
55        $this->offset = (int)$offset;
56        return $this;
57    }
58
59    /**
60     * Builds the SQL for the pagination, based on the DB engine
61     *
62     * @return  string
63     */
64    public function buildPaginateSQL()
65    {
66        if ($this->limit === null) {
67            return '';
68        }
69
70        return 'LIMIT ' . (($this->offset != 0) ? $this->offset . ', ' . $this->limit : $this->limit);
71    }
72
73    /**
74     * Resets the LIMIT portion of this query to none.
75     *
76     * @return  $this
77     */
78    public function resetLimit()
79    {
80        $this->limit = null;
81        return $this;
82    }
83
84    /**
85     * Resets the OFFSET portion of this query to 0.
86     *
87     * @return  $this
88     */
89    public function resetOffset()
90    {
91        $this->offset = 0;
92        return $this;
93    }
94}

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    }