Completed
Push — master ( 7b17ad...a29029 )
by Tom
02:30
created

Attribute::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 2 Features 0
Metric Value
c 8
b 2
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 9
nc 3
nop 2
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\Pseudo;
8
class Attribute implements \Transphporm\Pseudo {
9
	private $functionSet;
10
11
	public function __construct(\Transphporm\FunctionSet $functionSet) {
12
		$this->functionSet = $functionSet;
13
	}
14
15
	public function match($pseudo, \DomElement $element) {
16
		$pos = strpos($pseudo, '[');
17
		if ($pos === false) return true;
18
19
		$name = substr($pseudo, 0, $pos);
20
		if (!$this->functionSet->hasFunction($name)) return true;
21
22
		$this->functionSet->setElement($element);
23
		$valueParser = new \Transphporm\Parser\Value($this->functionSet);
24
		$valueParser->debug = true;
25
		return $valueParser->parse($pseudo)[0];
26
	}
27
}
28