Total Complexity | 3 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | final class PostRepository |
||
12 | { |
||
13 | /** |
||
14 | * @var array<int, Post> |
||
15 | */ |
||
16 | private array $posts; |
||
17 | |||
18 | /** |
||
19 | * @param array<int, Post>|null $posts |
||
20 | */ |
||
21 | 10 | public function __construct(?array $posts = null) |
|
22 | { |
||
23 | 10 | $this->posts = $posts ?? [ |
|
24 | 10 | 1 => new Post(1, 'Post #1', new DateTimeImmutable('+1 day')), |
|
25 | 10 | 2 => new Post(2, 'Post #2', new DateTimeImmutable('+2 day')), |
|
26 | 10 | 3 => new Post(3, 'Post #3', new DateTimeImmutable('+3 day')), |
|
27 | ]; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return Post[] |
||
32 | */ |
||
33 | 3 | public function findAll(): array |
|
34 | { |
||
35 | 3 | return array_values($this->posts); |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param int $id |
||
40 | * @return Post|null |
||
41 | */ |
||
42 | 7 | public function findById(int $id): ?Post |
|
45 | } |
||
46 | } |
||
47 |