Completed
Pull Request — master (#20)
by Vladimir
02:43
created

RepeaterPageView::getRepeaterPermalinks()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
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 2016 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Object;
9
10
use allejo\stakx\FrontMatter\ExpandedValue;
11
12
class RepeaterPageView extends PageView
13
{
14
    /**
15
     * An iterator for the permalinks used in order for this entity to be treated as a static PageView
16
     *
17
     * @var \ArrayIterator
18
     */
19
    private $permalinksIterator;
20
21
    /**
22
     * All of the expanded permalinks
23
     *
24
     * @var ExpandedValue
25
     */
26
    private $permalinks;
27
28
    /**
29
     * All of expanded redirects that should point to the respective permalink; this is estimated by index
30
     *
31
     * @var ExpandedValue[]
32
     */
33
    private $redirects;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function __construct($filePath)
39
    {
40 1
        parent::__construct($filePath);
41
42 1
        $this->type = PageView::REPEATER_TYPE;
43
44 1
        $this->configureValues();
45 1
    }
46
47
    /**
48
     * Get the expanded values for the permalinks to this PageView
49
     *
50
     * @return ExpandedValue
51
     */
52 1
    public function getRepeaterPermalinks ()
53
    {
54 1
        return $this->permalinks;
55
    }
56
57
    /**
58
     * Get the expanded values for the redirects pointing to this PageView
59
     *
60
     * @return ExpandedValue[]
61
     */
62 1
    public function getRepeaterRedirects ()
63
    {
64 1
        return $this->redirects;
65
    }
66
67
    /**
68
     * When looping through permalinks in a RepeaterPageView, the permalink needs to be updated each time so that it may
69
     * behave as a static PageView.
70
     */
71 1
    public function bumpPermalink ()
72
    {
73 1
        $this->permalink = $this->permalinksIterator->current()->getEvaluated();
74 1
        $this->permalinksIterator->next();
75 1
    }
76
77
    /**
78
     * Rewind the permalink iterator to the beginning
79
     */
80
    public function resetPermalink ()
81
    {
82
        $this->permalinksIterator->rewind();
83
    }
84
85
    /**
86
     * Setup this object
87
     */
88 1
    private function configureValues ()
89
    {
90
        // Cause the Front Matter to be evaluated
91 1
        $this->getFrontMatter();
92
93 1
        $evaluated = $this->frontMatter['permalink'];
94
95 1
        $this->permalinks = $evaluated[0];
96 1
        array_shift($evaluated);
97 1
        $this->redirects = $evaluated;
98
99 1
        $this->permalinksIterator = new \ArrayIterator($this->permalinks);
100 1
        $this->configured = true;
0 ignored issues
show
Bug introduced by
The property configured does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
101
    }
102
}