HistoryDao   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
dl 0
loc 30
ccs 0
cts 21
cp 0
rs 10
c 1
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A ratingHistory() 0 21 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Game\Infrastructure\Dao\Doctrine;
6
7
use App\Game\Features\History\HistoryDaoInterface;
8
use App\Game\Features\History\HistoryRatingDto;
9
use Doctrine\DBAL\Connection;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Connection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
final class HistoryDao implements HistoryDaoInterface
12
{
13
    private Connection $connection;
14
15
    public function __construct(Connection $connection)
16
    {
17
        $this->connection = $connection;
18
    }
19
20
    public function ratingHistory(int $limit = self::LIMIT): array
21
    {
22
        $records = $this->connection->createQueryBuilder()
23
            ->addSelect('p.nickname')
24
            ->addSelect('h.level')
25
            ->addSelect('(strftime("%s", max(h.createdAt)) - strftime("%s", min(H.createdAt))) as date')
26
            ->from('history', 'h')
27
            ->innerJoin('h', 'player', 'p', 'h.player = p.id')
28
            ->addOrderBy('date', 'ASC')
29
            ->addOrderBy('h.level', 'DESC')
30
            ->addGroupBy('p.nickname')
31
            ->setMaxResults($limit)
32
            ->execute()
33
            ->fetchAllAssociative();
34
35
        return array_map(
36
            static fn (array $record): HistoryRatingDto => new HistoryRatingDto(
37
                $record['nickname'],
38
                (int) $record['level']
39
            ),
40
            $records
41
        );
42
    }
43
}
44