Completed
Pull Request — master (#41)
by Vladimir
04:25
created

DynamicPageView::getCollection()   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
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Object;
9
10
class DynamicPageView extends PageView
11
{
12
    /**
13
     * The Content Items that belong to this Page View. This array will only have elements if it is a dynamic Page View.
14
     *
15
     * @var ContentItem[]
16
     */
17
    private $contentItems;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 4
    public function __construct($filePath)
23
    {
24 4
        parent::__construct($filePath);
25
26 4
        $this->contentItems = array();
27 4
        $this->type = PageView::DYNAMIC_TYPE;
28 4
    }
29
30
    /**
31
     * Add a ContentItem to this Dynamic PageView.
32
     *
33
     * @param ContentItem $contentItem
34
     */
35 3
    public function addContentItem(&$contentItem)
36
    {
37 3
        $filename = $this->fs->getBaseName($contentItem->getFilePath());
38
39 3
        $this->contentItems[$filename] = &$contentItem;
40 3
        $contentItem->setPageView($this);
41 3
    }
42
43
    /**
44
     * Get all of the ContentItems that belong to this Dynamic PageView.
45
     *
46
     * @return ContentItem[]
47
     */
48 2
    public function getContentItems()
49
    {
50 2
        return $this->contentItems;
51
    }
52
53
    /**
54
     * Get the collection name this dynamic PageView is charged with.
55
     *
56
     * @return string
57
     */
58 3
    public function getCollection()
59
    {
60 3
        return $this->getFrontMatter(false)['collection'];
61
    }
62
}
63