DBLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 28.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 36
ccs 4
cts 14
cp 0.2857
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 20 2
1
<?php
2
3
namespace Webcook\Cms\I18nBundle\Loader;
4
5
use Symfony\Component\Translation\Loader\LoaderInterface;
6
use Symfony\Component\Translation\MessageCatalogue;
7
use Doctrine\Common\Persistence\ObjectManager;
8
9
class DBLoader implements LoaderInterface
10
{
11
    private $translationsRepository;
12
13
    private $languageRepository;
14
 
15
    /**
16
     * @param ObjectManager $entityManager
17
     */
18 1
    public function __construct(ObjectManager $entityManager)
19
    {
20 1
        $this->translationsRepository = $entityManager->getRepository("Webcook\Cms\I18nBundle\Entity\Translation");
21 1
        $this->languageRepository     = $entityManager->getRepository("Webcook\Cms\I18nBundle\Entity\Language");
22 1
    }
23
 
24
    public function load($resource, $locale, $domain = 'messages')
25
    {
26
        // TODO write just one query join on locale
27
        $language = $this->languageRepository->findOneBy(array(
28
            'locale' => $locale
29
        ));
30
31
        $translations = $this->translationsRepository->findBy(array(
32
            'language'  => $language,
33
            'catalogue' => $domain
34
        ));
35
 
36
        $catalogue = new MessageCatalogue($locale);
37
 
38
        foreach ($translations as $translation) {
39
            $catalogue->set($translation->getKey(), $translation->getTranslation(), $domain);
40
        }
41
 
42
        return $catalogue;
43
    }
44
}
45