Completed
Push — master ( 52b075...cc4ebe )
by Tom
03:34
created

Not::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 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\Pseudo;
8
class Not implements \Transphporm\Pseudo {
9
	private $dataFunction;
10
11
	public function __construct(\Transphporm\Hook\DataFunction $dataFunction) {
12
		$this->dataFunction = $dataFunction;
13
	}
14
15
	public function match($pseudo, \DomElement $element) {
16
		if (strpos($pseudo, 'not') === 0) {
17
			$valueParser = new \Transphporm\Parser\Value($this->dataFunction);
18
			$bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo);
19
			$css = explode(',', $bracketMatcher->match('(', ')'));
20
21
			foreach ($css as $selector) {
22
				$cssToXpath = new \Transphporm\Parser\CssToXpath($selector, $valueParser);
23
				$xpathString = $cssToXpath->getXpath();	
24
				$xpath = new \DomXpath($element->ownerDocument);
25
				
26
				foreach ($xpath->query($xpathString) as $matchedElement) {
27
					if ($element->isSameNode($matchedElement)) return false;
28
				}
29
			}
30
		}
31
		return true;
32
	}
33
}