Completed
Pull Request — master (#61)
by Vladimir
03:02
created

DynamicPageView::getIndexName()   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 2
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
use allejo\stakx\Filesystem\File;
11
12
class DynamicPageView extends BasePageView
13
{
14
    /** @var CollectableItem[] */
15
    private $collectableItems = [];
16
17
    /**
18
     * DynamicPageView constructor.
19
     */
20 4
    public function __construct(File $file)
21
    {
22 4
        parent::__construct($file);
23
24 4
        $this->type = BasePageView::DYNAMIC_TYPE;
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getIndexName()
31
    {
32
        return $this->getCollectableNamespace();
33
    }
34
35
    /**
36
     * Add a CollectableItem for this PageView to handle.
37
     */
38
    public function addCollectableItem(CollectableItem &$collectable)
39
    {
40
        $this->collectableItems[$collectable->getRelativeFilePath()] = &$collectable;
41
        $collectable->setParentPageView($this);
42
    }
43
44
    /**
45
     * Delete a CollectableItem from this PageView.
46
     */
47
    public function delCollectableItem(CollectableItem &$collectableItem)
48
    {
49
        unset($this->collectableItems[$collectableItem->getRelativeFilePath()]);
50
    }
51
52
    /**
53
     * Get all of the CollectableItems handled by this PageView.
54
     *
55
     * @return CollectableItem[]|TemplateReadyDocument[]|ReadableDocument[]
56
     */
57
    public function getCollectableItems()
58
    {
59
        return $this->collectableItems;
60
    }
61
62
    /**
63
     * Get the namespace this PageView is handling.
64
     *
65
     * @return string
66
     */
67
    public function getCollectableNamespace()
68
    {
69
        $fm = $this->getRawFrontMatter();
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...
70
71
        if (isset($fm['collection']))
72
        {
73
            return $fm['collection'];
74
        }
75
76
        return $fm['dataset'];
77
    }
78
}
79