Completed
Push — master ( 14a89c...6d8b44 )
by Vladimir
11s
created

setCompiledOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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