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

LotteryTicketRepository::truncateAllLotteryTickets()   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 Doctrine\ORM\Query\ResultSetMapping;
9
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...
10
use Stu\Orm\Entity\LotteryTicket;
11
12
/**
13
 * @extends EntityRepository<LotteryTicket>
14
 */
15
final class LotteryTicketRepository extends EntityRepository implements LotteryTicketRepositoryInterface
16
{
17
    #[Override]
18
    public function prototype(): LotteryTicket
19
    {
20
        return new LotteryTicket();
21
    }
22
23
    #[Override]
24
    public function save(LotteryTicket $lotteryticket): void
25
    {
26
        $em = $this->getEntityManager();
27
28
        $em->persist($lotteryticket);
29
    }
30
31 1
    #[Override]
32
    public function getAmountByPeriod(string $period): int
33
    {
34 1
        return $this->count([
35 1
            'period' => $period
36 1
        ]);
37
    }
38
39 1
    #[Override]
40
    public function getAmountByPeriodAndUser(string $period, int $userId): int
41
    {
42 1
        return $this->count([
43 1
            'period' => $period,
44 1
            'user_id' => $userId
45 1
        ]);
46
    }
47
48
    #[Override]
49
    public function getByPeriod(string $period): array
50
    {
51
        return $this->findBy(['period' => $period, 'is_winner' => null]);
52
    }
53
54 1
    #[Override]
55
    public function getLotteryHistory(): array
56
    {
57 1
        $rsm = new ResultSetMapping();
58 1
        $rsm->addScalarResult('period', 'period');
59 1
        $rsm->addScalarResult('amount', 'amount', 'integer');
60
61 1
        return $this->getEntityManager()
62 1
            ->createNativeQuery(
63 1
                'SELECT lt.period AS period, count(lt.id) AS amount
64
                FROM stu_lottery_ticket lt
65
                WHERE lt.is_winner IS NOT NULL
66
                GROUP BY lt.period
67
                ORDER BY lt.period DESC
68 1
                LIMIT 24',
69 1
                $rsm
70 1
            )
71 1
            ->getResult();
72
    }
73
}
74