Lines
100.00%
10 / 10
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Values | 100.00% | 10 / 10 | 100.00% | 3 / 3 | 6 | 100.00% | 1 / 1 | |||
| values | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | |||||
| value | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | |||||
| resetValues | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Query\Builder; | |
| 4 | ||
| 5 | /** | |
| 6 | * Values | |
| 7 | * | |
| 8 | * Used by INSERT and UPDATE to se the values for the write-query. | |
| 9 | * | |
| 10 | * @package BO\Zmsbackend\Query\Builder | |
| 11 | * @author Alex Gisby<alex@solution10.com> | |
| 12 | * @license MIT | |
| 13 | */ | |
| 14 | trait 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 | } |