Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
CRAP | |
56.25% |
9 / 16 |
Validator | |
0.00% |
0 / 1 |
|
60.00% |
3 / 5 |
13.36 | |
56.25% |
9 / 16 |
__construct($dataType, $instance, $strict = true) | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
validate() | |
0.00% |
0 / 1 |
4.12 | |
50.00% |
3 / 6 |
|||
getDefault() | |
100.00% |
1 / 1 |
1 | ||||||
__set($varName, $value) | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
_getDataValidator() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
/** | |
* | |
*/ | |
namespace aae\data { | |
/** | |
* @author Axel Ancona Esselmann | |
* @package aae\data | |
*/ | |
class Validator implements ValidatorInterface { | |
public $validatorFactory = null; | |
private $_instance = null, $_dataType, $_strict = false; | |
public function __construct($dataType, $instance, $strict = true) { | |
$this->validatorFactory = new \aae\data\ValidatorFactory($dataType); | |
$this->_instance = $instance; | |
$this->_dataType = (string)$dataType; | |
$this->_strict = (bool)$strict; | |
} | |
public function validate() { | |
$dataValidator = $this->_getDataValidator(); | |
if ($dataValidator->validate() === true) { | |
return $this->_instance; | |
} else if ($this->_strict === false) { | |
return $dataValidator->getDefault(); | |
} else { | |
throw new \Exception("Error Processing Request", 211141615); | |
} | |
} | |
public function getDefault() {} | |
public function __set($varName, $value) { | |
if ($varName == "strict") { | |
$this->_strict = (bool)$value; | |
} | |
return $this; | |
} | |
protected function _getDataValidator() { | |
return $this->validatorFactory->build(); | |
} | |
} | |
} |