| Total Complexity | 4 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final readonly class DatabaseValidator implements ValidatorInterface |
||
|
|
|||
| 14 | { |
||
| 15 | public function __construct( |
||
| 16 | private ContainerInterface $dic, |
||
| 17 | private ConfigProviderInterface $configProvider, |
||
| 18 | ) { |
||
| 19 | } |
||
| 20 | |||
| 21 | public function validate(): void |
||
| 22 | { |
||
| 23 | $dsn = $this->configProvider->getDatabaseDsn(); |
||
| 24 | |||
| 25 | if ($dsn === '') { |
||
| 26 | throw new EnvironmentValidationException( |
||
| 27 | 'Database DSN is not set in config' |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | |||
| 31 | try { |
||
| 32 | $this->dic->get(EntityManagerInterface::class)->getConnection()->connect(); |
||
| 33 | } catch (Throwable $throwable) { |
||
| 34 | throw new EnvironmentValidationException( |
||
| 35 | 'Database connection could not be established', |
||
| 36 | 0, |
||
| 37 | $throwable |
||
| 38 | ); |
||
| 42 |