Passed
Push — master ( db8d74...f13993 )
by Atanas
01:54
created

View::getGlobals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\View;
4
5
use Closure;
6
use WPEmerge\Helpers\Handler;
7
use WPEmerge\Support\Arr;
8
9
/**
10
 * Render view files with php
11
 */
12
class View {
13
	/**
14
	 * Global variables
15
	 *
16
	 * @var array
17
	 */
18
	protected $globals = [];
19
20
	/**
21
	 * View composers
22
	 *
23
	 * @var array
24
	 */
25
	protected $composers = [];
26
27
	/**
28
	 * Get global variables
29
	 *
30
	 * @return array
31
	 */
32 2
	public function getGlobals() {
33 2
		return $this->globals;
34
	}
35
36
	/**
37
	 * Set a global variable
38
	 *
39
	 * @param  string $key
40
	 * @param  mixed  $value
41
	 * @return void
42
	 */
43 1
	public function setGlobal( $key, $value ) {
44 1
		$this->globals[ $key ] = $value;
45 1
	}
46
47
	/**
48
	 * Set an array of global variables
49
	 *
50
	 * @param  array $globals
51
	 * @return void
52
	 */
53 1
	public function setGlobals( $globals ) {
54 1
		foreach ( $globals as $key => $value ) {
55 1
			$this->setGlobal( $key, $value );
56 1
		}
57 1
	}
58
59
	/**
60
	 * Get view composer
61
	 *
62
	 * @param  string       $view
63
	 * @return Handler|null
64
	 */
65 1
	public function getComposer( $view ) {
66 1
		return Arr::get( $this->composers, $view, null );
67
	}
68
69
	/**
70
	 * Set view composer
71
	 *
72
	 * @param  string         $view
73
	 * @param  string|Closure $composer
74
	 * @return void
75
	 */
76 1
	public function setComposer( $view, $composer ) {
77 1
		$handler = new Handler( $composer );
78 1
		$this->composers[ $view ] = $handler;
79 1
	}
80
81
	/**
82
	 * Get the composed context for a view.
83
	 * Passes all arguments to the composer.
84
	 *
85
	 * @param  string $view
86
	 * @param  mixed  $arguments,...
0 ignored issues
show
Bug introduced by
There is no parameter named $arguments,.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
87
	 * @return array
88
	 */
89 2
	public function compose( $view ) {
90 2
		$composer = $this->getComposer( $view );
91 2
		if ( $composer === null ) {
92 1
			return [];
93
		}
94 1
		return call_user_func_array( [$composer, 'execute'], func_get_args() );
95
	}
96
}
97