| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4.128 |
| Changes | 0 | ||
| 1 | <?php |
||
| 30 | 38 | public function chosen() : ?Connection |
|
| 31 | { |
||
| 32 | 38 | if (empty($this->filename)) { |
|
| 33 | 37 | return null; |
|
| 34 | } |
||
| 35 | |||
| 36 | 38 | if (! file_exists($this->filename)) { |
|
| 37 | 37 | return null; |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | $params = include $this->filename; |
|
| 41 | |||
| 42 | 1 | if (! is_array($params)) { |
|
| 43 | throw new InvalidArgumentException( |
||
| 44 | 'The connection file has to return an array with database configuration parameters.' |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | |||
| 48 | 1 | return DriverManager::getConnection($params); |
|
| 49 | } |
||
| 51 |