Passed
Push — dev ( 526fc6...1b8890 )
by Nico
35:41
created

PirateWrathRepository::getPirateWrathTop10()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 14
ccs 0
cts 11
cp 0
crap 2
rs 9.9332
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\PirateWrath;
10
use Stu\Orm\Entity\PirateWrathInterface;
11
12
/**
13
 * @extends EntityRepository<PirateWrath>
14
 *
15
 * @method PirateWrathInterface[] findAll()
16
 */
17
final class PirateWrathRepository extends EntityRepository implements PirateWrathRepositoryInterface
18
{
19
    #[Override]
20
    public function save(PirateWrathInterface $wrath): void
21
    {
22
        $em = $this->getEntityManager();
23
24
        $em->persist($wrath);
25
    }
26
27
    #[Override]
28
    public function delete(PirateWrathInterface $wrath): void
29
    {
30
        $em = $this->getEntityManager();
31
32
        $em->remove($wrath);
33
    }
34
35
    #[Override]
36
    public function prototype(): PirateWrathInterface
37
    {
38
        return new PirateWrath();
39
    }
40
41
    #[Override]
42
    public function truncateAllEntries(): void
43
    {
44
        $this->getEntityManager()->createQuery(
45
            sprintf(
46
                'DELETE FROM %s pw',
47
                PirateWrath::class
48
            )
49
        )->execute();
50
    }
51
52
    /**
53
     * @return PirateWrathInterface[]
54
     */
55
    #[Override]
56
    public function getPirateWrathTop10(): array
57
    {
58
        return $this->getEntityManager()
59
            ->createQuery(
60
                sprintf(
61
                    'SELECT pw
62
            FROM %s pw
63
            ORDER BY pw.wrath DESC',
64
                    PirateWrath::class
65
                )
66
            )
67
            ->setMaxResults(10)
68
            ->getResult();
69
    }
70
71
    #[Override]
72
    public function truncateByUser(int $userId): void
73
    {
74
        $this->getEntityManager()
75
            ->createQuery(
76
                sprintf(
77
                    'DELETE FROM %s pw WHERE pw.user_id = :userId',
78
                    PirateWrath::class
79
                )
80
            )
81
            ->setParameter('userId', $userId)
82
            ->execute();
83
    }
84
}