Lines
98.71%
77 / 78
Methods
95.65%
22 / 23
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| sql | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | ||
| 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\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 | ||
| 14 | class Delete extends Query | |
| 15 | { | |
| 16 | use TableName; | |
| 17 | use Where; | |
| 18 | use Paginate; | |
| 19 | ||
| 20 | /** | |
| 21 | * @var string The base part of the query | |
| 22 | */ | |
| 23 | protected $queryBase = 'DELETE FROM'; | |
| 24 | ||
| 25 | /** | |
| 26 | * Generates the full SQL statement for this query with all the composite parts. | |
| 27 | * | |
| 28 | * @return string | |
| 29 | */ | |
| 30 | #[\Override] | |
| 31 | public function sql() | |
| 32 | { | |
| 33 | if ($this->table === null) { | |
| 34 | return ''; | |
| 35 | } | |
| 36 | ||
| 37 | $candidateParts = [ | |
| 38 | $this->queryBase, | |
| 39 | $this->dialect->quoteTable($this->table), | |
| 40 | $this->buildWhereSQL($this->dialect), | |
| 41 | $this->buildPaginateSQL() | |
| 42 | ]; | |
| 43 | ||
| 44 | return trim(implode(' ', $candidateParts)); | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Returns all the parameters, in the correct order, to pass into PDO. | |
| 49 | * | |
| 50 | * @return array | |
| 51 | */ | |
| 52 | #[\Override] | |
| 53 | public function params() | |
| 54 | { | |
| 55 | return $this->getWhereParams(); | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Resets the entire query. | |
| 60 | * | |
| 61 | * @return $this | |
| 62 | */ | |
| 63 | #[\Override] | |
| 64 | public function reset() | |
| 65 | { | |
| 66 | $this->table = null; | |
| 67 | $this->resetWhere(); | |
| 68 | return $this; | |
| 69 | } | |
| 70 | ||
| 71 | /* | |
| 72 | * ------------------- All Tables ------------------------ | |
| 73 | */ | |
| 74 | ||
| 75 | /** | |
| 76 | * Returns all the tables that this query makes mention of, in FROMs and JOINs | |
| 77 | * | |
| 78 | * @return array | |
| 79 | */ | |
| 80 | #[\Override] | |
| 81 | public function allTablesReferenced() | |
| 82 | { | |
| 83 | if ($this->table()) { | |
| 84 | return [$this->table()]; | |
| 85 | } | |
| 86 | return []; | |
| 87 | } | |
| 88 | } |
From BO\Zmsbackend\Query\Builder\TableName
| 14 | trait 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\Where
| 30 | trait 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
| 15 | trait 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 | } |