Completed
Pull Request — master (#87)
by Vladimir
02:24
created

CompileProcessPostRenderPageView   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 44
ccs 6
cts 13
cp 0.4615
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCompiledOutput() 0 4 1
A setCompiledOutput() 0 11 2
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 allejo\stakx\Utilities\StrUtils;
11
use Symfony\Component\EventDispatcher\Event;
12
13
/**
14
 * This event is triggered after a PageView is compiled and before it is written to a file. The compiled output is
15
 * accessible and can be modified before it is written out to a file.
16
 *
17
 * @since 0.2.0
18
 */
19
class CompileProcessPostRenderPageView extends Event
20
{
21
    const NAME = 'compile.process.postrender_pageview';
22
23
    private $compiledOutput;
24
    private $pageViewType;
25
26
    /**
27
     * CompileProcessPostRenderPageView constructor.
28
     *
29
     * @param string $pageViewType
30
     * @param string $compiledOutput
31
     */
32 12
    public function __construct($pageViewType, $compiledOutput)
33
    {
34 12
        $this->compiledOutput = $compiledOutput;
35 12
        $this->pageViewType = $pageViewType;
36 12
    }
37
38
    /**
39
     * @return string
40
     */
41 12
    public function getCompiledOutput()
42
    {
43 12
        return (string)$this->compiledOutput;
44
    }
45
46
    /**
47
     * Modify the compiled output.
48
     *
49
     * @param string $compiledOutput
50
     */
51
    public function setCompiledOutput($compiledOutput)
52
    {
53
        if (StrUtils::canBeCastedToString($compiledOutput))
54
        {
55
            @trigger_error('CompileProcessPostRenderPageView :: Value cannot be set to something that cannot be cast into a string.', E_USER_WARNING);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
56
57
            return;
58
        }
59
60
        $this->compiledOutput = $compiledOutput;
61
    }
62
}
63