| Total Complexity | 7 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | trait HasMeta |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array stores the meta items for this class |
||
| 11 | */ |
||
| 12 | protected array $_meta = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Returns the meta items |
||
| 16 | * |
||
| 17 | * @param string|null $key the key to return |
||
| 18 | * @param string|null $default a default if the $key is missing |
||
| 19 | * @return mixed |
||
| 20 | */ |
||
| 21 | public function meta(string $key = null, string $default = null): mixed |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Adds items to the meta content optionally replacing existing keys |
||
| 36 | * |
||
| 37 | * @param $fields |
||
| 38 | */ |
||
| 39 | public function addMeta($fields, $replace = false): void |
||
| 40 | { |
||
| 41 | if ($replace) { |
||
| 42 | $this->_meta = array_merge($this->_meta, $fields); |
||
| 43 | } |
||
| 44 | $this->_meta = array_merge($fields, $this->_meta); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Replaces a meta item |
||
| 49 | * |
||
| 50 | * @param $key |
||
| 51 | * @param $value |
||
| 52 | */ |
||
| 53 | public function replaceMeta($key, $value): void |
||
| 54 | { |
||
| 55 | $this->_meta[$key] = $value; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns the UUID of the Block |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | public function uuid(): string |
||
| 65 | } |
||
| 66 | } |