| Conditions | 5 |
| Paths | 4 |
| Total Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | 15 | public function create(string $database, ?array $locales = null): Reader |
|
| 45 | { |
||
| 46 | 15 | if (!array_key_exists($database, $this->databases)) { |
|
| 47 | 6 | $databases = implode('", "', array_keys($this->databases)); |
|
| 48 | |||
| 49 | 6 | throw new \InvalidArgumentException(sprintf('Undefined "%s" database. Available "%s" databases.', $database, $databases)); |
|
| 50 | } |
||
| 51 | |||
| 52 | 9 | if (!is_array($this->databases[$database]) || empty($this->databases[$database]['path'])) { |
|
| 53 | 6 | throw new \InvalidArgumentException(sprintf('Database "%s" is not configured.', $database)); |
|
| 54 | } |
||
| 55 | |||
| 56 | 3 | if ($locales === null) { |
|
| 57 | 1 | $locales = $this->databases[$database]['locales'] ?? ['en']; |
|
| 58 | } |
||
| 59 | |||
| 60 | 3 | return new $this->reader_class($this->databases[$database]['path'], $locales); |
|
| 61 | } |
||
| 62 | } |
||
| 63 |