Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
21 | final readonly class DatabaseStorage implements StorageInterface |
||
|
|||
22 | { |
||
23 | 3 | public function __construct(private PDO $pdo, private DatabaseStorageConfig $databaseStorageConfig) {} |
|
24 | |||
25 | /** |
||
26 | * @inheritDoc |
||
27 | */ |
||
28 | 3 | #[\Override] |
|
29 | public function loadTemplate(string $templateName): string |
||
30 | { |
||
31 | 3 | $stmt = $this->pdo->prepare( |
|
32 | 3 | \sprintf( |
|
33 | 3 | 'SELECT %s FROM %s WHERE %s = :name', |
|
34 | 3 | $this->databaseStorageConfig->contentField, |
|
35 | 3 | $this->databaseStorageConfig->tableName, |
|
36 | 3 | $this->databaseStorageConfig->nameField |
|
37 | 3 | ) |
|
38 | 3 | ); |
|
39 | |||
40 | 3 | $stmt->execute(['name' => $templateName]); |
|
41 | |||
42 | /** |
||
43 | * @var false|string $content |
||
44 | */ |
||
45 | 3 | $content = $stmt->fetchColumn(); |
|
46 | |||
47 | 3 | if ($content === false) { |
|
48 | 1 | throw TemplateNotFoundException::forDatabaseTemplate($templateName); |
|
49 | } |
||
58 |