Completed
Push — master ( 89bfcf...4ab803 )
by Vladimir
02:41
created

DynamicPageView::getDataset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
/**
11
 * A dynamic PageView is created when the following keywords are found in the FrontMatter of a PageView:
12
 *
13
 *   - collection
14
 *   - dataset
15
 *
16
 * This PageView type will contain references to all of the RepeatableItems
17
 */
18
class DynamicPageView extends PageView
19
{
20
    /**
21
     * The RepeatableItems that belong to this PageView.
22
     *
23
     * @var RepeatableItem[]
24
     */
25
    private $repeatableItems;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 6
    public function __construct($filePath)
31
    {
32 6
        parent::__construct($filePath);
33
34 6
        $this->repeatableItems = array();
35 6
        $this->type = PageView::DYNAMIC_TYPE;
36 6
    }
37
38
    /**
39
     * Add a RepeatableItem to this dynamic PageView.
40
     *
41
     * @param RepeatableItem $repeatableItem
42
     */
43 5
    public function addRepeatableItem(RepeatableItem &$repeatableItem)
44
    {
45 5
        $this->repeatableItems[$repeatableItem->getObjectName()] = &$repeatableItem;
46 5
        $repeatableItem->setParentPageView($this);
47 5
    }
48
49
    /**
50
     * Remove a RepeatableItem from the list of items that this dynamic PageView is responsible for.
51
     *
52
     * @param RepeatableItem $repeatableItem
53
     */
54
    public function delRepeatableItem(RepeatableItem &$repeatableItem)
55
    {
56
        unset($this->repeatableItems[$repeatableItem->getObjectName()]);
57
    }
58
59
    /**
60
     * Get all of the RepeatableItem that belong to this dynamic PageView.
61
     *
62
     * @return RepeatableItem[]
63
     */
64 4
    public function getRepeatableItems()
65
    {
66 4
        return $this->repeatableItems;
67
    }
68
69 3
    public function getRepeatableNamespace()
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...
70
    {
71 3
        $fm = $this->getFrontMatter(false);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $fm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
72
73 3
        if (isset($fm['collection']))
74
        {
75 3
            return $fm['collection'];
76
        }
77
78
        return $fm['dataset'];
79
    }
80
81 3
    public function getObjectName()
82
    {
83 3
        return $this->getRepeatableNamespace();
84
    }
85
}
86