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

RepeaterPageView::configureValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 17
ccs 13
cts 13
cp 1
crap 2
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
    public function getRepeaterRedirects ()
49
    {
50
        $this->configureValues();
51
52
        return $this->redirects;
53
    }
54
55 1
    public function bump ()
56
    {
57 1
        $this->permalink = $this->permalinksIterator->current()->getEvaluated();
58 1
        $this->redirects = $this->redirectsIterator->current();
59
60 1
        $this->permalinksIterator->next();
61 1
        $this->redirectsIterator->next();
62 1
    }
63
64 1
    private function configureValues ()
65
    {
66 1
        if (!$this->configured)
67 1
        {
68 1
            $this->getFrontMatter();
69 1
            $evaluated = $this->frontMatter['permalink'];
70
71 1
            $this->permalinks = $evaluated[0];
72 1
            array_shift($evaluated);
73 1
            $this->redirects = $evaluated;
74
75 1
            $this->permalinksIterator = new \ArrayIterator($this->permalinks);
76 1
            $this->redirectsIterator  = new \ArrayIterator($this->redirects);
77
78 1
            $this->configured = true;
79 1
        }
80
    }
81
}