Passed
Push — master ( d2acd0...7e642c )
by Julito
09:19
created

SettingsResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 13
c 1
b 1
f 0
dl 0
loc 30
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 15 3
A __construct() 0 3 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Settings;
6
7
use Doctrine\ORM\NonUniqueResultException;
8
use Sylius\Bundle\SettingsBundle\Resolver\SettingsResolverInterface;
9
use Sylius\Bundle\SettingsBundle\Resource\RepositoryInterface;
10
11
class SettingsResolver implements SettingsResolverInterface
12
{
13
    /**
14
     * @var RepositoryInterface
15
     */
16
    private $settingsRepository;
17
18
    /**
19
     * @param RepositoryInterface $settingsRepository
20
     */
21
    public function __construct(RepositoryInterface $settingsRepository)
22
    {
23
        $this->settingsRepository = $settingsRepository;
24
    }
25
26
    public function resolve($schemaAlias, $namespace = null)
27
    {
28
        try {
29
            $criteria = [];
30
            if (null !== $namespace) {
31
                $criteria['category'] = $namespace;
32
            }
33
34
            return $this->settingsRepository->findBy($criteria);
35
        } catch (NonUniqueResultException $e) {
36
            $message = sprintf(
37
                'Multiple schemas found for "%s". You should probably define a custom settings resolver for this schema.',
38
                $schemaAlias
39
            );
40
            throw new \LogicException($message);
41
        }
42
    }
43
}
44