Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the return type of DriverManager::getAvailableDrivers()
- Loading branch information
1 parent
fb248c8
commit 9ed1ebc
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
static-analysis/driver-manager-get-available-drivers-return-type.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); |