Passed
Pull Request — master (#1716)
by Nico
23:15
created

UserSettingRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prototype() 0 3 1
A delete() 0 5 1
A truncateByUser() 0 10 1
A save() 0 5 1
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\UserInterface;
9
use Stu\Orm\Entity\UserSetting;
10
use Stu\Orm\Entity\UserSettingInterface;
11
12
/**
13
 * @extends EntityRepository<UserSetting>
14
 */
15
final class UserSettingRepository extends EntityRepository implements UserSettingRepositoryInterface
16
{
17
    public function prototype(): UserSettingInterface
18
    {
19
        return new UserSetting();
20
    }
21
22
    public function save(UserSettingInterface $userSetting): void
23
    {
24
        $em = $this->getEntityManager();
25
26
        $em->persist($userSetting);
27
    }
28
29
    public function delete(UserSettingInterface $userSetting): void
30
    {
31
        $em = $this->getEntityManager();
32
33
        $em->remove($userSetting);
34
    }
35
36
    public function truncateByUser(UserInterface $user): void
37
    {
38
        $this->getEntityManager()->createQuery(
39
            sprintf(
40
                'DELETE FROM %s us WHERE us.user_id = :userId',
41
                UserSetting::class
42
            )
43
        )->setParameters([
44
            'userId' => $user->getId(),
45
        ])->execute();
46
    }
47
}
48