Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| CallableTester | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| testValue | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getCallable | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setCallable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
| 5 | */ |
| 6 | |
| 7 | declare(strict_types=1); |
| 8 | |
| 9 | namespace pvc\validator\val_tester\callable; |
| 10 | |
| 11 | use pvc\interfaces\validator\valtesters\ValTesterCallableInterface; |
| 12 | |
| 13 | /** |
| 14 | * Class CallableTester |
| 15 | * @template DateType |
| 16 | * @implements ValTesterCallableInterface<DateType> |
| 17 | */ |
| 18 | class CallableTester implements ValTesterCallableInterface |
| 19 | { |
| 20 | /** |
| 21 | * @var callable|null |
| 22 | */ |
| 23 | protected $callable; |
| 24 | |
| 25 | public function __construct(callable $callable) |
| 26 | { |
| 27 | $this->setCallable($callable); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * testValue |
| 32 | * @param $value |
| 33 | * @return bool |
| 34 | */ |
| 35 | public function testValue($value): bool |
| 36 | { |
| 37 | $callable = $this->getCallable(); |
| 38 | return (bool)$callable($value); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * getCallable |
| 43 | * @return callable |
| 44 | */ |
| 45 | public function getCallable(): callable |
| 46 | { |
| 47 | /** @phpcs noinspection */ |
| 48 | $default = function (mixed $value) { return true; }; |
| 49 | return ($this->callable ?? $default); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * setCallable |
| 54 | * @param callable $callable |
| 55 | */ |
| 56 | public function setCallable(callable $callable): void |
| 57 | { |
| 58 | $this->callable = $callable; |
| 59 | } |
| 60 | } |