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

Not   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B match() 0 18 5
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
}