DoctrineSettingRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 38
ccs 0
cts 22
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findWithinSection() 0 9 1
A save() 0 9 1
1
<?php
2
3
namespace Galileo\SettingBundle\Lib\Infrastructure\Framework;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Galileo\SettingBundle\Lib\Model\Setting;
7
use Galileo\SettingBundle\Lib\Model\SettingRepositoryInterface;
8
use Galileo\SettingBundle\Lib\Model\ValueObject\Key;
9
use Galileo\SettingBundle\Lib\Model\ValueObject\Section;
10
11
class DoctrineSettingRepository implements SettingRepositoryInterface
12
{
13
    /**
14
     * @var EntityManagerInterface
15
     */
16
    private $entityManager;
17
18
    public function __construct(EntityManagerInterface $entityManager)
19
    {
20
        $this->entityManager = $entityManager;
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function findWithinSection(Key $settingKey, Section $settingSection)
27
    {
28
        return $this->entityManager->getRepository('GalileoSettingBundle:Setting')->findOneBy(
29
            [
30
                'name' => $settingKey->key(),
31
                'section' => $settingSection->name(),
32
            ]
33
        );
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function save(Setting $setting)
40
    {
41
        $this->entityManager->transactional(
42
            function () use ($setting){
43
                $this->entityManager->persist($setting);
44
                $this->entityManager->flush();
45
            }
46
        );
47
    }
48
}
49