for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/* @description Transformation Style Sheets - Revolutionising PHP templating *
* @author Tom Butler [email protected] *
* @copyright 2015 Tom Butler <[email protected]> | https://r.je/ *
* @license http://www.opensource.org/licenses/bsd-license.php BSD License *
* @version 1.0 */
namespace Transphporm\Pseudo;
class Nth implements \Transphporm\Pseudo {
public function match($pseudo, \DomElement $element) {
if (strpos($pseudo, 'nth-child') === 0) {
$bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo);
$criteria = $bracketMatcher->match('(', ')');
$bracketMatcher = new \Transphporm\Parser\BracketMatcher($element->getNodePath());
$num = $bracketMatcher->match('[', ']');
if (is_callable([$this, $criteria])) return $this->$criteria($num);
else return $num == $criteria;
}
return true;
private function odd($num) {
return $num % 2 === 1;
private function even($num) {
return $num % 2 === 0;