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

ShipTakeoverRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 39
ccs 0
cts 19
cp 0
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prototype() 0 4 1
A delete() 0 6 1
A save() 0 6 1
A getByTargetOwner() 0 15 1
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