Completed
Push — master ( b00e9b...6e0e0e )
by Vladimir
03:28
created

StaticPageView::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Document;
9
10
use allejo\stakx\Filesystem\File;
11
12
class StaticPageView extends BasePageView implements TemplateReadyDocument
13
{
14
    /** @var JailedDocument */
15
    private $jailInstance;
16
17
    /** @var JailedDocument[] */
18
    private $jailedChildPageViews;
19
20
    /** @var StaticPageView[] */
21
    private $childPageViews = [];
22
23
    /**
24
     * StaticPageView constructor.
25
     */
26 30
    public function __construct(File $file)
27
    {
28 30
        $this->type = BasePageView::STATIC_TYPE;
29
30 30
        parent::__construct($file);
31 30
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 22
    public function createJail()
37
    {
38 22
        if ($this->jailInstance === null)
39
        {
40 22
            $whiteListedFunctions = array_merge(self::$whiteListedFunctions, [
41
42 22
            ]);
43
44
            $jailedFunctions = [
45 22
                'getChildren' => 'getJailedChildren',
46
            ];
47
48 22
            $this->jailInstance = new JailedDocument($this, $whiteListedFunctions, $jailedFunctions);
49
        }
50
51 22
        return $this->jailInstance;
52
    }
53
54
    /**
55
     * Get child PageViews.
56
     *
57
     * A child is defined as a static PageView whose URL has a parent. For example, a PageView with a URL of
58
     * `/gallery/france/` would have the PageView whose URL is `/gallery` as a parent.
59
     *
60
     * @return StaticPageView[]
61
     */
62 3
    public function &getChildren()
63
    {
64 3
        return $this->childPageViews;
65
    }
66
67
    /**
68
     * Get the child PageViews.
69
     *
70
     * @return JailedDocument[]
71
     */
72 3
    public function getJailedChildren()
73
    {
74 3
        if ($this->jailedChildPageViews === null)
75
        {
76 3
            $this->jailedChildPageViews = [];
77
78 3
            foreach ($this->childPageViews as $key => &$child)
79
            {
80 3
                $this->jailedChildPageViews[$key] = $child->createJail();
81
            }
82
        }
83
84 3
        return $this->jailedChildPageViews;
85
    }
86
87
    /**
88
     * Get the PageView's body written in a templating language.
89
     *
90
     * @return string
91
     */
92 10
    public function getContent()
93
    {
94 10
        return $this->bodyContent;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 View Code Duplication
    public function jsonSerialize()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        return array_merge($this->getFrontMatter(), [
103
            'content'   => $this->getContent(),
104
            'permalink' => $this->getPermalink(),
105
            'redirects' => $this->getRedirects(),
106
        ]);
107
    }
108
109 10
    protected function beforeCompile()
110
    {
111 10
        $this->buildPermalink(true);
112 10
    }
113
}
114