Completed
Push — master ( c2b5cc...89bfcf )
by Vladimir
03:33
created

DynamicPageView   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 3
dl 0
loc 75
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getDataset() 0 4 1
A addRepeatableItem() 0 7 1
A getRepeatableItems() 0 4 1
A getCollection() 0 4 1
A getRepeatableName() 0 11 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
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 $repeatableItems;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 6
    public function __construct($filePath)
23
    {
24 6
        parent::__construct($filePath);
25
26 6
        $this->repeatableItems = array();
27 6
        $this->type = PageView::DYNAMIC_TYPE;
28 6
    }
29
30
    /**
31
     * Add a ContentItem to this Dynamic PageView.
32
     *
33
     * @param TwigDocumentInterface $repeatableItem
34
     */
35 5
    public function addRepeatableItem(&$repeatableItem)
36
    {
37 5
        $filename = $this->fs->getBaseName($repeatableItem->getFilePath());
38
39 5
        $this->repeatableItems[$filename] = &$repeatableItem;
40 5
        $repeatableItem->setPageView($this);
41 5
    }
42
43
    /**
44
     * Get all of the ContentItems that belong to this Dynamic PageView.
45
     *
46
     * @return ContentItem[]
47
     */
48 4
    public function getRepeatableItems()
49
    {
50 4
        return $this->repeatableItems;
51
    }
52
53
    /**
54
     * Get the collection name this dynamic PageView is charged with.
55
     *
56
     * @return string
57
     */
58
    public function getCollection()
59
    {
60
        return $this->getFrontMatter(false)['collection'];
61
    }
62
63
    /**
64
     * Get the dataset name this dynamic PageView is charged with.
65
     *
66
     * @return string
67
     */
68
    public function getDataset()
69
    {
70
        return $this->getFrontMatter(false)['dataset'];
71
    }
72
73 3
    public function getRepeatableName()
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...
74
    {
75 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...
76
77 3
        if (isset($fm['collection']))
78
        {
79 3
            return $fm['collection'];
80
        }
81
82
        return $fm['dataset'];
83
    }
84
}
85