Completed
Pull Request — master (#88)
by Vladimir
02:11
created

CompileProcessPreRenderPageView   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 39
ccs 6
cts 12
cp 0.5
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPageViewType() 0 4 1
A getCustomVariables() 0 9 2
A appendCustomVariables() 0 4 1
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Event;
9
10
use Symfony\Component\EventDispatcher\Event;
11
12
/**
13
 * This event is fired before a PageView is rendered and allows you inject custom variables into the templates.
14
 *
15
 * @since 0.2.0
16
 */
17
class CompileProcessPreRenderPageView extends Event
18
{
19
    const NAME = 'compile.process.prerender_pageview';
20
21
    private $customVariables = [];
22
    private $pageViewType;
23
24 12
    public function __construct($pageViewType)
25
    {
26 12
        $this->pageViewType = $pageViewType;
27 12
    }
28
29
    public function getPageViewType()
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...
30
    {
31
        return $this->pageViewType;
32
    }
33
34 12
    public function getCustomVariables()
35
    {
36 12
        if (!is_array($this->customVariables))
37
        {
38
            return [];
39
        }
40
41 12
        return $this->customVariables;
42
    }
43
44
    /**
45
     * Append custom variables that'll be made available as template variables in PageViews.
46
     *
47
     * @param array $customVariables
48
     *
49
     * @since 0.2.0
50
     */
51
    public function appendCustomVariables(array $customVariables)
52
    {
53
        $this->customVariables = array_merge($this->customVariables, $customVariables);
54
    }
55
}
56