| Total Complexity | 8 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 14 | class Connect |
||
| 15 | { |
||
| 16 | public static string $connection = 'sqlite'; |
||
| 17 | private static ?PDOException $error = null; |
||
| 18 | |||
| 19 | |||
| 20 | /** |
||
| 21 | * @param array|null $database |
||
| 22 | * @return PDO|null |
||
| 23 | */ |
||
| 24 | public static function getInstance(array $database = null) |
||
| 25 | { |
||
| 26 | $pdo = ConnectionFactory::createConnection($database); |
||
| 27 | if ($pdo) { |
||
|
|
|||
| 28 | MigrationManager::migrate($pdo); |
||
| 29 | } |
||
| 30 | return $pdo; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $connection |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public static function setConnection(string $connection) |
||
| 38 | { |
||
| 39 | $drivers = ['mysql', 'sqlite', 'pgsql']; |
||
| 40 | if (!in_array($connection, $drivers)) { |
||
| 41 | throw ConnectionException::create("Only ['MySQL(mysql)', 'SQLite(sqlite)', 'PgSQL(pgsql)'] are available at the moment..."); |
||
| 42 | } |
||
| 43 | self::$connection = $connection; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | public static function getConnection() |
||
| 50 | { |
||
| 51 | return self::$connection; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return PDOException|null |
||
| 56 | */ |
||
| 57 | public static function getError() |
||
| 58 | { |
||
| 59 | return self::$error; |
||
| 60 | } |
||
| 61 | |||
| 62 | private function __construct() {} |
||
| 63 | private function __clone() {} |
||
| 64 | } |
||
| 65 |