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

Nth::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4286
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 Nth implements \Transphporm\Pseudo {
9
	
10
	public function match($pseudo, \DomElement $element) {
11
		if (strpos($pseudo, 'nth-child') === 0) {
12
			$bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo);
13
			$criteria = $bracketMatcher->match('(', ')');
14
		
15
			$bracketMatcher = new \Transphporm\Parser\BracketMatcher($element->getNodePath());
16
			$num = $bracketMatcher->match('[', ']');
17
			
18
			if (is_callable([$this, $criteria])) return $this->$criteria($num);
19
			else return $num == $criteria;			
20
		}
21
		return true;
22
	}
23
24
	private function odd($num) {
25
		return $num % 2 === 1;
26
	}
27
28
	private function even($num) {
29
		return $num % 2 === 0;
30
	}
31
}