Passed
Push — dev ( 842324...d0c170 )
by Janko
14:41
created

ShipTakeoverRepository::getByTargetOwner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 11
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 15
ccs 0
cts 11
cp 0
crap 2
rs 9.9
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\ShipTakeover;
10
use Stu\Orm\Entity\ShipTakeoverInterface;
11
use Stu\Orm\Entity\Spacecraft;
12
use Stu\Orm\Entity\UserInterface;
13
14
/**
15
 * @extends EntityRepository<ShipTakeover>
16
 */
17
final class ShipTakeoverRepository extends EntityRepository implements ShipTakeoverRepositoryInterface
18
{
19
    #[Override]
20
    public function prototype(): ShipTakeoverInterface
21
    {
22
        return new ShipTakeover();
23
    }
24
25
    #[Override]
26
    public function save(ShipTakeoverInterface $shipTakeover): void
27
    {
28
        $em = $this->getEntityManager();
29
30
        $em->persist($shipTakeover);
31
    }
32
33
    #[Override]
34
    public function delete(ShipTakeoverInterface $shipTakeover): void
35
    {
36
        $em = $this->getEntityManager();
37
38
        $em->remove($shipTakeover);
39
    }
40
41
    #[Override]
42
    public function getByTargetOwner(UserInterface $user): array
43
    {
44
        return $this->getEntityManager()->createQuery(
45
            sprintf(
46
                'SELECT sto FROM %s sto
47
                JOIN %s sp
48
                WITH sto.target = sp
49
                WHERE sp.user = :user',
50
                ShipTakeover::class,
51
                Spacecraft::class
52
            )
53
        )
54
            ->setParameter('user', $user)
55
            ->getResult();
56
    }
57
}
58