Passed
Push — dev ( 00d352...e70ec0 )
by Nico
05:38
created

WormholeRestrictionRepository::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 4
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\Component\Ship\Wormhole\WormholeEntryTypeEnum;
10
use Stu\Orm\Entity\WormholeRestriction;
11
use Stu\Orm\Entity\WormholeEntry;
12
13
/**
14
 * @extends EntityRepository<WormholeRestriction>
15
 */
16
final class WormholeRestrictionRepository extends EntityRepository implements WormholeRestrictionRepositoryInterface
17
{
18
    #[Override]
19
    public function prototype(): WormholeRestriction
20
    {
21
        return new WormholeRestriction();
22
    }
23
24
    #[Override]
25
    public function save(WormholeRestriction $restriction): void
26
    {
27
        $em = $this->getEntityManager();
28
        $em->persist($restriction);
29
    }
30
31
    #[Override]
32
    public function delete(WormholeRestriction $restriction): void
33
    {
34
        $em = $this->getEntityManager();
35
36
        $em->remove($restriction);
37
        $em->flush();
38
    }
39
40
    #[Override]
41
    public function existsForTargetAndTypeAndEntry(int $targetId, ?WormholeEntryTypeEnum $privilegeType, WormholeEntry $wormholeEntry): bool
42
    {
43
        return $this->count([
44
            'wormholeEntry' => $wormholeEntry,
45
            'target' => $targetId,
46
            'privilege_type' => $privilegeType,
47
        ]) > 0;
48
    }
49
50
    #[Override]
51
    public function truncateByTypeAndTarget(?WormholeEntryTypeEnum $type, int $targetId): void
52
    {
53
        $this->getEntityManager()
54
            ->createQuery(
55
                sprintf(
56
                    'DELETE FROM %s wr WHERE wr.target = :targetId AND wr.privilege_type = :typeId',
57
                    WormholeRestriction::class
58
                )
59
            )
60
            ->setParameters([
61
                'typeId' => $type,
62
                'targetId' => $targetId,
63
            ])
64
            ->execute();
65
    }
66
}
67