InMemoryHistoryDao   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 34
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ratingHistory() 0 5 1
A histories() 0 3 1
A __construct() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Game\Infrastructure\Dao\InMemory;
6
7
use App\Game\Features\History\History;
8
use App\Game\Features\History\HistoryDaoInterface;
9
use App\Game\Features\History\HistoryRatingDto;
10
11
final class InMemoryHistoryDao implements HistoryDaoInterface
12
{
13
    /**
14
     * @var History[]
15
     */
16
    private array $histories;
17
18
    public function __construct(History ...$history)
19
    {
20
        $this->histories = array_reduce(
21
            $history,
22
            static function (array $histories, History $history): array {
23
                $histories[(string) $history->historyId()] = $history;
24
25
                return $histories;
26
            },
27
            []
28
        );
29
    }
30
31
    public function ratingHistory(int $limit = self::LIMIT): array
32
    {
33
        return array_map(
34
            static fn (History $history): HistoryRatingDto => new HistoryRatingDto('test', $history->level()),
35
            $this->histories
36
        );
37
    }
38
39
    /**
40
     * @return History[]
41
     */
42
    public function histories(): array
43
    {
44
        return $this->histories;
45
    }
46
}
47