Passed
Push — master ( beb509...f9654e )
by Richard
03:40 queued 11s
created

HasMeta::uuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
7
trait HasMeta
8
{
9
	/**
10
	 * @var array stores the meta items for this class
11
	 */
12
	protected $_meta = [];
13
14
	/**
15
	 * Returns the meta items
16
	 *
17
	 * @param null $key the key to return
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $key is correct as it would always require null to be passed?
Loading history...
18
	 * @param null $default a default if the $key is missing
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
19
	 * @return array
20
	 */
21
	public function meta($key = null, $default = null) {
22
		if ($key) {
0 ignored issues
show
introduced by
$key is of type null, thus it always evaluated to false.
Loading history...
23
			if (array_key_exists($key, $this->_meta)) {
24
				return $this->_meta[$key];
25
			} else {
26
				return $default;
27
			}
28
		}
29
30
		return $this->_meta;
31
	}
32
33
	/**
34
	 * Adds items to the meta content keeping any that already exist
35
	 *
36
	 * @param $fields
37
	 */
38
	public function addMeta($fields) {
39
		$this->_meta = array_merge($fields, $this->_meta);
40
	}
41
42
	/**
43
	 * Replaces a meta item
44
	 *
45
	 * @param $key
46
	 * @param $value
47
	 */
48
	public function replaceMeta($key, $value) {
49
		$this->_meta[$key] = $value;
50
	}
51
52
	/**
53
	 * Returns the UUID of the Block
54
	 * @return string
55
	 */
56
	public function uuid() {
57
		return $this->meta('_uid');
58
	}
59
}