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

Nth   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 24
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 13 3
A odd() 0 3 1
A even() 0 3 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 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
}