Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
8 / 8 |
Not | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
8 / 8 |
__construct | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
validate | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
<?php | |
namespace Verja\Validator; | |
use Verja\Validator; | |
use Verja\ValidatorInterface; | |
class Not extends Validator | |
{ | |
/** @var ValidatorInterface */ | |
protected $validator; | |
/** | |
* Not constructor. | |
* | |
* @param ValidatorInterface|string $validator | |
*/ | |
public function __construct($validator) | |
{ | |
if (!$validator instanceof ValidatorInterface) { | |
$validator = Validator::fromString($validator); | |
} | |
$this->validator = $validator; | |
} | |
/** | |
* Validate $value | |
* | |
* @param mixed $value | |
* @param array $context | |
* @return bool | |
*/ | |
public function validate($value, array $context = []): bool | |
{ | |
if ($this->validator->validate($value, $context)) { | |
$this->error = $this->validator->getInverseError($value); | |
return false; | |
} | |
return true; | |
} | |
} |