Completed
Push — master ( aa44e7...3b6d57 )
by Tom
02:09
created

Last::traverse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 0
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
/** Parses "string" and function(args) e.g. data(foo) or iteration(bar) */
9
class Last {
10
	private $baseData;
0 ignored issues
show
Unused Code introduced by
The property $baseData is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
	private $autoLookup;
12
	/*
13
		Stores the last value e.g.
14
			"a" + "b"
15
		Will store "a" before reading the token for the + and perfoming the concatenate operation
16
	*/
17
	private $last;
18
	private $data;
19
	private $result;
20
	private $traversing = false;
21
22
23
	public function __construct($data, $result, $autoLookup) {
24
		$this->data = $data;
25
		$this->result = $result;
26
		$this->autoLookup = $autoLookup;
27
	}
28
29
30
	public function traverse() {
31
		if ($this->last !== null) $this->data->traverse($this->last);
32
		else {
33
			$lastResult = $this->result->pop();
0 ignored issues
show
Bug introduced by
The method pop cannot be called on $this->result (of type array<integer,false,{"0":"false"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34
			if ($lastResult) {
35
				$this->data = new ValueData($lastResult);
36
				return $lastResult;
37
			}
38
		}
39
	}
40
41
	public function clear() {
42
		$this->last = null;
43
	}
44
45
	public function isEmpty() {
46
		return $this->last == null;
47
	}
48
49
	public function processNested($parser, $token) {		
50
		$funcResult = $this->data->parseNested($parser, $token, $this->last);
51
		$this->result->processValue($funcResult);
0 ignored issues
show
Bug introduced by
The method processValue cannot be called on $this->result (of type array<integer,false,{"0":"false"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
52
		$this->last = null;
53
	}
54
55
	public function read() {
56
		return $this->last;
57
	}
58
59
	public function set($value) {
60
		$this->last = $value;
61
	}
62
63
64
	//Applies the current operation to whatever is in $last based on $mode
65 View Code Duplication
	public function process() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
		if ($this->last !== null) {
67
			try {
68
				$value = $this->data->extract($this->last, $this->autoLookup, $this->traversing);
69
				$this->result->processValue($value);
0 ignored issues
show
Bug introduced by
The method processValue cannot be called on $this->result (of type array<integer,false,{"0":"false"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
70
			}
71
			catch (\UnexpectedValueException $e) {
72
				$this->processLastUnexpected();
73
			}
74
		}
75
	}
76
77 View Code Duplication
	private function processLastUnexpected() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
		if (!($this->autoLookup || $this->traversing)) {
79
			$this->result->processValue($this->last);
80
		}
81
		else {
82
			$this->result->clear();
83
			$this->result[0] = false;
84
		}
85
	}
86
}