Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 3.0175 |
Changes | 0 |
1 | <?php |
||
29 | 5 | public static function create($connection_options) |
|
30 | { |
||
31 | $drivers = [ |
||
32 | 5 | "Oci8" => "Drone\Db\Driver\Oracle", |
|
33 | "Mysqli" => "Drone\Db\Driver\MySQL", |
||
34 | "Sqlsrv" => "Drone\Db\Driver\SQLServer", |
||
35 | ]; |
||
36 | |||
37 | 5 | if (!array_key_exists('driver', $connection_options)) |
|
|
|||
38 | throw new \RuntimeException("The database driver key has not been declared"); |
||
39 | |||
40 | 5 | $drv = $connection_options["driver"]; |
|
41 | |||
42 | 5 | if (array_key_exists($drv, $drivers)) |
|
43 | 4 | return new $drivers[$drv]($connection_options); |
|
44 | else |
||
45 | 1 | throw new \RuntimeException("The database driver does not exists"); |
|
46 | } |
||
47 | } |
Adding braces to control structures avoids accidental mistakes as your code changes: