Passed
Pull Request — master (#1809)
by Nico
49:28 queued 23:38
created

PirateWrathRepository::getPirateWrathTop10()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 13
ccs 0
cts 11
cp 0
crap 2
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Stu\Orm\Entity\PirateWrath;
9
use Stu\Orm\Entity\PirateWrathInterface;
10
use Stu\Orm\Entity\User;
11
12
/**
13
 * @extends EntityRepository<PirateWrath>
14
 *
15
 * @method PirateWrathInterface[] findAll()
16
 */
17
final class PirateWrathRepository extends EntityRepository implements PirateWrathRepositoryInterface
18
{
19
    public function save(PirateWrathInterface $wrath): void
20
    {
21
        $em = $this->getEntityManager();
22
23
        $em->persist($wrath);
24
    }
25
26
    public function delete(PirateWrathInterface $wrath): void
27
    {
28
        $em = $this->getEntityManager();
29
30
        $em->remove($wrath);
31
    }
32
33
    public function prototype(): PirateWrathInterface
34
    {
35
        return new PirateWrath();
36
    }
37
38
    public function truncateAllEntries(): void
39
    {
40
        $this->getEntityManager()->createQuery(
41
            sprintf(
42
                'DELETE FROM %s pw',
43
                PirateWrath::class
44
            )
45
        )->execute();
46
    }
47
48
    /**
49
     * @return PirateWrathInterface[]
50
     */
51
    public function getPirateWrathTop10(): array
52
    {
53
        return $this->getEntityManager()
54
            ->createQuery(
55
                sprintf(
56
                    'SELECT pw
57
            FROM %s pw
58
            ORDER BY pw.wrath DESC',
59
                    PirateWrath::class
60
                )
61
            )
62
            ->setMaxResults(10)
63
            ->getResult();
64
    }
65
}
66