Data::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.2                                                             */
7
namespace Transphporm\TSSFunction;
8
/* Handles data() and iteration() function calls from the stylesheet */
9
class Data implements \Transphporm\TSSFunction{
10
	private $data;
11
	private $dataKey;
12
	private $functionSet;
13
14
	public function __construct(\Transphporm\Hook\ElementData $data, \Transphporm\FunctionSet $functionSet, $dataKey = 'data') {
15
		$this->data = $data;
16
		$this->dataKey = $dataKey;
17
		$this->functionSet = $functionSet;
18
	}
19
20
	public function run(array $args, \DomElement $element = null) {
21
		if ($this->dataKey === "root") $data = $this->data->getData(null, 'data');
22
		else $data = $this->data->getData($element, $this->dataKey);
23
		$parser = new \Transphporm\Parser\Value($this->functionSet, true, true);
24
		$return = $parser->parseTokens(new \Transphporm\Parser\Tokens($args), $data);
25
		return $return[0];
26
	}
27
}
28