Completed
Pull Request — master (#69)
by Vladimir
05:36
created

ExpandedValue::getIterators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 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\FrontMatter;
9
10
/**
11
 * Class ExpandedValue.
12
 *
13
 * An instance of this object is created to store the values and information related to the "value expansion" feature of
14
 * the FrontMatter parser
15
 */
16
class ExpandedValue
17
{
18
    /**
19
     * Store the original value with variables and this value will be updated in-place as it's evaluated.
20
     *
21
     * @var string
22
     */
23
    private $evaluated;
24
25
    /**
26
     * The definition of variable replacements that occurred for this specific string.
27
     *
28
     * The $key for the array would be the variable name without the % and the $value would be literal value that
29
     * replaced the variable in the string
30
     *
31
     * @var string[]
32
     */
33
    private $iterators;
34
35
    /**
36
     * ExpandedValue constructor.
37
     *
38
     * @param string $string
39
     */
40 5
    public function __construct($string)
41
    {
42 5
        $this->evaluated = $string;
43 5
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    public function __toString()
49
    {
50 1
        return $this->getEvaluated();
51
    }
52
53
    /**
54
     * Get the current evaluated string.
55
     *
56
     * If the evaluation in FrontMatterParser hasn't been completed, this will return the partially evaluated string
57
     * variables still in place.
58
     *
59
     * @return string
60
     */
61 5
    public function getEvaluated()
62
    {
63 5
        return $this->evaluated;
64
    }
65
66
    /**
67
     * Update the currently evaluated string.
68
     *
69
     * As the string is being evaluated in the FrontMatterParser, this value will be updated as variables are iterated
70
     * through.
71
     *
72
     * @param string $string
73
     */
74 4
    public function setEvaluated($string)
75
    {
76 4
        $this->evaluated = $string;
77 4
    }
78
79
    /**
80
     * Get all of the variable replacements that were used in this evaluated string.
81
     *
82
     * @return string[]
83
     */
84
    public function getIterators()
85
    {
86
        return $this->iterators;
87
    }
88
89
    /**
90
     * Record the value of a variable replacement.
91
     *
92
     * The variable name should NOT contain the % and the value should be as-is
93
     *
94
     * @param string     $variableName
95
     * @param string|int $variableValue
96
     */
97 4
    public function setIterator($variableName, $variableValue)
98
    {
99 4
        $this->iterators[$variableName] = $variableValue;
100 4
    }
101
}
102