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

RepeaterPageView::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
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
     * @var \ArrayIterator
16
     */
17
    private $permalinksIterator;
18
19
    /**
20
     * @var \ArrayIterator
21
     */
22
    private $redirectsIterator;
23
24
    private $permalinks;
25
    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...
26
27
    private $configured;
28
29 1
    public function __construct($filePath)
30
    {
31 1
        parent::__construct($filePath);
32
33 1
        $this->frontMatterBlacklist = array();
34 1
        $this->type = PageView::REPEATER_TYPE;
35 1
        $this->configured = false;
36 1
    }
37
38
    /**
39
     * @return ExpandedValue[]
40
     */
41 1
    public function getRepeaterPermalinks ()
42
    {
43 1
        $this->configureValues();
44
45 1
        return $this->permalinks;
46
    }
47
48 1
    public function getRepeaterRedirects ()
49
    {
50 1
        $this->configureValues();
51
52 1
        return $this->redirects;
53
    }
54
55 1
    public function bumpPermalink ()
56
    {
57 1
        $this->permalink = $this->permalinksIterator->current()->getEvaluated();
58 1
        $this->permalinksIterator->next();
59 1
    }
60
61 1
    private function configureValues ()
62
    {
63 1
        if ($this->configured) { return; }
64
65
        // Cause the Front Matter to be evaluated
66 1
        $this->getFrontMatter();
67
68 1
        $evaluated = $this->frontMatter['permalink'];
69
70 1
        $this->permalinks = $evaluated[0];
71 1
        array_shift($evaluated);
72 1
        $this->redirects = $evaluated;
73
74 1
        $this->permalinksIterator = new \ArrayIterator($this->permalinks);
75 1
        $this->redirectsIterator  = new \ArrayIterator($this->redirects);
76
77 1
        $this->configured = true;
78
    }
79
}