Passed
Pull Request — master (#1904)
by Nico
39:29 queued 12:01
created

PirateWrathRepository::getByUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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