Completed
Push — master ( 808f8c...952fde )
by Vladimir
11s
created

DynamicPageView   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 96
ccs 16
cts 26
cp 0.6153
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getIndexName() 0 4 1
A addCollectableItem() 0 5 1
A delCollectableItem() 0 4 1
A getCollectableItem() 0 9 2
A hasCollectableItem() 0 4 1
A getCollectableItems() 0 4 1
A getCollectableNamespace() 0 11 2
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/stakx-io/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 3
    public function getIndexName()
31
    {
32 3
        return $this->getCollectableNamespace();
33
    }
34
35
    /**
36
     * Add a CollectableItem for this PageView to handle.
37
     */
38 3
    public function addCollectableItem(CollectableItem &$collectable)
39
    {
40 3
        $this->collectableItems[$collectable->getRelativeFilePath()] = &$collectable;
41 3
        $collectable->saveParentPageView($this);
42 3
    }
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 the Collectable Item based on its relative file path.
54
     *
55
     * @param string $relativeFilePath
56
     *
57
     * @return CollectableItem|TemplateReadyDocument|ReadableDocument|null
58
     */
59
    public function &getCollectableItem($relativeFilePath)
60
    {
61
        if (!$this->hasCollectableItem($relativeFilePath))
62
        {
63
            return null;
64
        }
65
66
        return $this->collectableItems[$relativeFilePath];
67
    }
68
69
    /**
70
     * Check whether or not this DynamicPageView manages a Collectable Item based on its relative path.
71
     *
72
     * @param string $relativeFilePath
73
     *
74
     * @return bool
75
     */
76
    public function hasCollectableItem($relativeFilePath)
77
    {
78
        return isset($this->collectableItems[$relativeFilePath]);
79
    }
80
81
    /**
82
     * Get all of the CollectableItems handled by this PageView.
83
     *
84
     * @return CollectableItem[]|TemplateReadyDocument[]|ReadableDocument[]
85
     */
86 2
    public function getCollectableItems()
87
    {
88 2
        return $this->collectableItems;
89
    }
90
91
    /**
92
     * Get the namespace this PageView is handling.
93
     *
94
     * @return string
95
     */
96 3
    public function getCollectableNamespace()
97
    {
98 3
        $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...
99
100 3
        if (isset($fm['collection']))
101
        {
102 3
            return $fm['collection'];
103
        }
104
105
        return $fm['dataset'];
106
    }
107
}
108