Completed
Push — master ( f9a7a2...eb8de6 )
by Tom
02:33
created

ValueResult   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 78
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A processValue() 0 10 1
A arg() 0 3 1
A concat() 0 3 1
A not() 0 3 1
A equals() 0 3 1
A setMode() 0 3 1
A getMode() 0 3 1
A getResult() 0 3 1
A pop() 0 3 1
A offsetSet() 0 3 1
A offsetGet() 0 3 1
A offsetUnset() 0 3 1
A offsetExists() 0 3 1
A clear() 0 3 1
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2015 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.0                                                             */
7
namespace Transphporm\Parser;
8
class ValueResult implements \ArrayAccess {
9
	private $result = [];
10
11
	/*
12
		The next operation to perform. Will be one of the following:
13
			ARG - A new value e.g,  "a","b"  becomes ["a", "b"]
14
			CONCAT - Concat onto the current arg e.g "a" + "b" becomes ["ab"]
15
			NOT - Boolean operation "a" != "b" becomes [true]
16
			EQUALS - Boolean operation "a" = "b" becomes [false]
17
	*/
18
	private $mode = Tokenizer::ARG;
19
	
20
	//Processes $newValue using $mode. Either concats to the current argument, adds a new argument
21
	//Or usess the two arguments for a boolean comparison
22
	public function processValue($newValue) {
23
		$funcs = [
24
			Tokenizer::ARG => 'arg',
25
			Tokenizer::CONCAT => 'concat',
26
			Tokenizer::EQUALS => 'equals',
27
			Tokenizer::NOT => 'not' 
28
		];
29
30
		$this->{$funcs[$this->mode]}($newValue);
31
	}
32
33
	public function arg($value) {
34
		$this->result[] = $value;
35
	}
36
37
	public function concat($value) {
38
		$this->result[count($this->result)-1] .= $value;
39
	}
40
41
	public function not($value) {
42
		$this->result[count($this->result)-1] = $this->result[count($this->result)-1] != $value;
43
	}
44
	
45
	public function equals($value) {
46
		$this->result[count($this->result)-1] = $this->result[count($this->result)-1] == $value;
47
	}
48
49
	
50
	public function setMode($mode) {
51
		$this->mode = $mode;
52
	}
53
54
	public function getMode() {
55
		return $this->mode;
56
	}
57
58
	public function getResult() {
59
		return $this->result;
60
	}
61
62
	public function pop() {
63
		return array_pop($this->result);
64
	}
65
66
	public function offsetSet($key, $value) {
67
		$this->result[$key] = $value;
68
	}
69
70
	public function offsetGet($key) {
71
		return $this->result[$key];
72
	}
73
74
	public function offsetUnset($key) {
75
		unset($this->result[$key]);
76
	}
77
78
	public function offsetExists($key) {
79
		return isset($this->result[$key]);
80
	}
81
82
	public function clear() {
83
		$this->result = [];
84
	}
85
}