Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
29 / 29 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SqlSystemRequirementsRepository | |
100.00% |
28 / 28 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getActiveRequirements | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
3 | |||
| getRequirementByKey | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\About\Infrastructure\Repository; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Modules\About\Domain\Model\SystemRequirement; |
| 12 | use App\Modules\About\Domain\Repository\SystemRequirementsRepositoryInterface; |
| 13 | use PDO; |
| 14 | |
| 15 | /** |
| 16 | * SQL System Requirements Repository. |
| 17 | * |
| 18 | * Implements persistence access for system benchmark definitions using PDO. |
| 19 | * |
| 20 | * @package App\Modules\About\Infrastructure\Repository |
| 21 | */ |
| 22 | final readonly class SqlSystemRequirementsRepository implements SystemRequirementsRepositoryInterface |
| 23 | { |
| 24 | /** |
| 25 | * SqlSystemRequirementsRepository constructor. |
| 26 | * |
| 27 | * @param PDO $pdo Database connection instance. |
| 28 | * @param string $tablePrefix Database table prefix. |
| 29 | */ |
| 30 | public function __construct( |
| 31 | private PDO $pdo, |
| 32 | private string $tablePrefix = 'a_' |
| 33 | ) { |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * {@inheritdoc} |
| 38 | */ |
| 39 | public function getActiveRequirements(?string $category = null): array |
| 40 | { |
| 41 | $tableName = $this->tablePrefix . 'core_system_requirements'; |
| 42 | |
| 43 | if ($category !== null && $category !== '') { |
| 44 | $sql = "SELECT `id`, `category`, `requirement_key`, `label`, `recommended_value`, `minimum_value`, |
| 45 | `severity`, `description`, `impact_on_failure`, `sort_order`, `is_active` |
| 46 | FROM `{$tableName}` |
| 47 | WHERE `is_active` = 1 AND `category` = :category |
| 48 | ORDER BY `sort_order` ASC, `id` ASC"; |
| 49 | $stmt = $this->pdo->prepare($sql); |
| 50 | $stmt->execute([':category' => $category]); |
| 51 | } else { |
| 52 | $sql = "SELECT `id`, `category`, `requirement_key`, `label`, `recommended_value`, `minimum_value`, |
| 53 | `severity`, `description`, `impact_on_failure`, `sort_order`, `is_active` |
| 54 | FROM `{$tableName}` |
| 55 | WHERE `is_active` = 1 |
| 56 | ORDER BY `category` ASC, `sort_order` ASC, `id` ASC"; |
| 57 | $stmt = $this->pdo->prepare($sql); |
| 58 | $stmt->execute(); |
| 59 | } |
| 60 | |
| 61 | /** @var array<int, array<string, mixed>> $rows */ |
| 62 | $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 63 | |
| 64 | return array_map( |
| 65 | static fn(array $row): SystemRequirement => SystemRequirement::fromArray($row), |
| 66 | $rows |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * {@inheritdoc} |
| 72 | */ |
| 73 | public function getRequirementByKey(string $key): ?SystemRequirement |
| 74 | { |
| 75 | $tableName = $this->tablePrefix . 'core_system_requirements'; |
| 76 | $sql = "SELECT `id`, `category`, `requirement_key`, `label`, `recommended_value`, `minimum_value`, |
| 77 | `severity`, `description`, `impact_on_failure`, `sort_order`, `is_active` |
| 78 | FROM `{$tableName}` |
| 79 | WHERE `requirement_key` = :key |
| 80 | LIMIT 1"; |
| 81 | |
| 82 | $stmt = $this->pdo->prepare($sql); |
| 83 | $stmt->execute([':key' => $key]); |
| 84 | /** @var array<string, mixed>|false $row */ |
| 85 | $row = $stmt->fetch(PDO::FETCH_ASSOC); |
| 86 | |
| 87 | if ($row === false) { |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | return SystemRequirement::fromArray($row); |
| 92 | } |
| 93 | } |