PostRepository::findAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Model\Post;
6
7
use DateTimeImmutable;
8
9
use function array_values;
10
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
43
    {
44 7
        return $this->posts[$id] ?? null;
45
    }
46
}
47