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

HasContextTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 0
cts 10
cp 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContext() 0 7 2
A with() 0 8 2
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