Passed
Push — master ( f2f9a5...aa567c )
by Atanas
01:53
created

HasContextTrait::getContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\View;
4
5
use WPEmerge\Support\Arr;
6
7
trait HasContextTrait {
8
	/**
9
	 * Context.
10
	 *
11
	 * @var array
12
	 */
13
	protected $context = [];
14
15
	/**
16
	 * Get context values.
17
	 *
18
	 * @param  string|null $key
19
	 * @return mixed
20
	 */
21 1
	public function getContext( $key = null ) {
22 1
		if ( $key === null ) {
23 1
			return $this->context;
24
		}
25
26
		return Arr::get( $this->context, $key );
27
	}
28
29
	/**
30
	 * Add context values.
31
	 *
32
	 * @param  string|array $key
33
	 * @param  mixed        $value
34
	 * @return self         $this
35
	 */
36 1
	public function with( $key, $value = null ) {
37 1
		if ( is_array( $key ) ) {
38 1
			$this->context = array_merge( $this->getContext(), $key );
39
		} else {
40 1
			$this->context[ $key ] = $value;
41
		}
42 1
		return $this;
43
	}
44
}
45