Completed
Pull Request — master (#41)
by Vladimir
02:38
created

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