Passed
Push — master ( a8bd8b...f2f9a5 )
by Atanas
02:01
created

HasContextTrait::getContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 6
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
	 * {@inheritDoc}
17
	 */
18
	public function getContext( $key = null ) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
19
		if ( $key === null ) {
20
			return $this->context;
21
		}
22
23
		return Arr::get( $this->context, $key );
24
	}
25
26
	/**
27
	 * {@inheritDoc}
28
	 */
29
	public function with( $key, $value = null ) {
30
		if ( is_array( $key ) ) {
31
			$this->context = array_merge( $this->getContext(), $key );
32
		} else {
33
			$this->context[ $key ] = $value;
34
		}
35
		return $this;
36
	}
37
}
38