DoctrineSettingRepository::findWithinSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
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