Passed
Push — master ( 8387eb...5a11dc )
by Janko
07:59
created

PrestigeLogRepository::truncateAllPrestigeLogs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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...
9
use Stu\Orm\Entity\PrestigeLog;
10
use Stu\Orm\Entity\User;
11
12
/**
13
 * @extends EntityRepository<PrestigeLog>
14
 */
15
final class PrestigeLogRepository extends EntityRepository implements PrestigeLogRepositoryInterface
16
{
17
    #[Override]
18
    public function save(PrestigeLog $log): void
19
    {
20
        $em = $this->getEntityManager();
21
22
        $em->persist($log);
23
    }
24
25
    #[Override]
26
    public function delete(PrestigeLog $log): void
27
    {
28
        $em = $this->getEntityManager();
29
30
        $em->remove($log);
31
    }
32
33
    #[Override]
34
    public function prototype(): PrestigeLog
35
    {
36
        return new PrestigeLog();
37
    }
38
39
    #[Override]
40
    public function getSumByUser(User $user): int
41
    {
42
        return (int) $this->getEntityManager()->createQuery(
43
            sprintf(
44
                'SELECT SUM(pl.amount) FROM %s pl
45
                WHERE pl.user_id = :userId',
46
                PrestigeLog::class
47
            )
48
        )->setParameters([
49
            'userId' => $user->getId()
50
        ])->getSingleScalarResult();
51
    }
52
53 1
    #[Override]
54
    public function getPrestigeHistory(User $user, int $maxResults): array
55
    {
56 1
        return $this->getEntityManager()
57 1
            ->createQuery(
58 1
                sprintf(
59 1
                    'SELECT pl FROM %s pl
60
                    WHERE pl.user_id = :userId
61 1
                    ORDER BY pl.id DESC',
62 1
                    PrestigeLog::class
63 1
                )
64 1
            )
65 1
            ->setParameters([
66 1
                'userId' => $user->getId()
67 1
            ])
68 1
            ->setMaxResults($maxResults)
69 1
            ->getResult();
70
    }
71
}
72