Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| StatementRepository | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| findByUserId | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Statement\Repository; |
| 6 | |
| 7 | use PDO; |
| 8 | use RuntimeException; |
| 9 | |
| 10 | final readonly class StatementRepository |
| 11 | { |
| 12 | public function __construct( |
| 13 | private PDO $pdo, |
| 14 | ) {} |
| 15 | |
| 16 | /** |
| 17 | * @return array<int, array<string, mixed>> |
| 18 | */ |
| 19 | public function findByUserId(int $userId): array |
| 20 | { |
| 21 | $sql = ' |
| 22 | SELECT |
| 23 | id::TEXT AS "id", |
| 24 | user_id AS "userId", |
| 25 | period, |
| 26 | type, |
| 27 | file_url AS "fileUrl", |
| 28 | generated_at AS "generatedAt" |
| 29 | FROM statements |
| 30 | WHERE user_id = :user_id |
| 31 | ORDER BY generated_at DESC |
| 32 | '; |
| 33 | |
| 34 | $stmt = $this->pdo->prepare($sql); |
| 35 | if ($stmt === false) { |
| 36 | throw new RuntimeException('Failed to prepare statement query'); |
| 37 | } |
| 38 | |
| 39 | $stmt->execute(['user_id' => $userId]); |
| 40 | |
| 41 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 42 | } |
| 43 | } |