| Conditions | 4 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4.3244 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 4 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
|
| 24 | { |
||
| 25 | 4 | if (!$rule instanceof TableExistsRule) { |
|
| 26 | throw new UnexpectedRuleException(TableExistsRule::class, $rule); |
||
| 27 | } |
||
| 28 | |||
| 29 | 4 | $result = new Result(); |
|
| 30 | |||
| 31 | try { |
||
| 32 | 4 | $tableSchema = $this->connection->getTableSchema($value); |
|
| 33 | } catch (\Yiisoft\Db\Exception\Exception $e) { |
||
| 34 | $tableSchema = null; |
||
| 35 | } |
||
| 36 | |||
| 37 | 4 | if ($tableSchema === null) { |
|
| 38 | 1 | $result->addError(sprintf('Table "%s" does not exist.', $value)); |
|
| 39 | 1 | return $result; |
|
| 40 | } |
||
| 41 | |||
| 42 | 3 | return $result; |
|
| 43 | } |
||
| 45 |