| Total Complexity | 6 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class IsInstanceOf implements Validator { |
||
| 8 | private $fqcn; |
||
| 9 | private $description; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @param string $fqcn |
||
| 13 | * @param string $description |
||
| 14 | * @throws Exception |
||
| 15 | */ |
||
| 16 | 8 | public function __construct($fqcn, $description = null) { |
|
| 17 | 8 | if (!$this->isValidClassName($fqcn)) |
|
| 18 | 1 | throw new Exception("Invalid Regex pattern: {$fqcn}"); |
|
| 19 | |||
| 20 | 7 | $this->fqcn = $fqcn; |
|
| 21 | 7 | $this->description = $description ?? "Must be an instance of {$fqcn}"; |
|
| 22 | 7 | } |
|
| 23 | |||
| 24 | 1 | public function getFqcn() { |
|
| 25 | 1 | return $this->fqcn; |
|
| 26 | } |
||
| 27 | |||
| 28 | 3 | public function validate($value) : bool { |
|
| 29 | 3 | return is_a($value, $this->fqcn); |
|
| 30 | } |
||
| 31 | |||
| 32 | 8 | protected function isValidClassName($fqcn) { |
|
| 34 | } |
||
| 35 | |||
| 36 | 2 | public function getDescription() { |
|
| 38 | } |
||
| 39 | } |