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

SettingsResolver::resolve()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 10
c 1
b 1
f 0
nc 5
nop 2
dl 0
loc 15
rs 9.9332
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