Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
17 / 17 |
Operator | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
17 / 17 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
parse | |
100.00% |
1 / 1 |
1 | |
100.00% |
8 / 8 |
|||
getMethodName | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
buildMethodMap | |
100.00% |
1 / 1 |
3 | |
100.00% |
4 / 4 |
<?php | |
namespace PHPixie\Database\Parser; | |
abstract class Operator | |
{ | |
protected $methodMap = array(); | |
protected $operators; | |
public function __construct() | |
{ | |
$this->buildMethodMap(); | |
} | |
public function parse($condition) | |
{ | |
$operator = $condition->operator(); | |
$method = $this->getMethodName($operator); | |
return $this->$method( | |
$condition->field(), | |
$operator, | |
$condition->values(), | |
$condition->isNegated() | |
); | |
} | |
protected function getMethodName($operator) | |
{ | |
if(!isset($this->methodMap[$operator])) | |
throw new \PHPixie\Database\Exception\Parser("The '{$operator}' operator is not supported"); | |
return 'parse'.ucfirst($this->methodMap[$operator]); | |
} | |
protected function buildMethodMap() | |
{ | |
foreach($this->operators as $method => $operators) | |
foreach($operators as $operator) | |
$this->methodMap[$operator] = $method; | |
} | |
} |