Skip to content

Commit

Permalink
Test the return type of DriverManager::getAvailableDrivers()
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightDesign committed Jan 3, 2023
1 parent fb248c8 commit 9ed1ebc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpstan.neon.dist
Expand Up @@ -3,6 +3,7 @@ parameters:
phpVersion: 80200
paths:
- src
- static-analysis
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
Expand Down
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\StaticAnalysis\DBAL;

use Doctrine\DBAL\DriverManager;
use RuntimeException;

use function getenv;
use function in_array;

$driver = getenv('DB_DRIVER');
if (! in_array($driver, DriverManager::getAvailableDrivers(), true)) {
throw new RuntimeException('Not a valid driver');
}

DriverManager::getConnection(['driver' => $driver]);

0 comments on commit 9ed1ebc

Please sign in to comment.