Completed
Push — master ( 3b7ffc...93bca7 )
by Łukasz
15:02
created

resolverHasParameter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 3
dl 0
loc 11
c 0
b 0
f 0
cc 3
nop 3
rs 9.9
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver;
10
11
use eZ\Publish\Core\MVC\Exception\ParameterNotFoundException;
12
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
13
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
14
15
/**
16
 * @property-read \Symfony\Component\DependencyInjection\ContainerInterface $container
17
 *
18
 * @internal
19
 */
20
class SiteAccessGroupConfigResolver extends SiteAccessConfigResolver
21
{
22
    use ContainerAwareTrait;
23
24
    protected function resolverHasParameter(SiteAccess $siteAccess, string $paramName, string $namespace): bool
25
    {
26
        foreach ($siteAccess->groups as $group) {
27
            $groupScopeParamName = $this->resolveScopeRelativeParamName($paramName, $namespace, $group->getName());
28
            if ($this->container->hasParameter($groupScopeParamName)) {
29
                return true;
30
            }
31
        }
32
33
        return false;
34
    }
35
36
    protected function getParameterFromResolver(SiteAccess $siteAccess, string $paramName, string $namespace)
37
    {
38
        $triedScopes = [];
39
40
        foreach ($siteAccess->groups as $group) {
41
            $groupScopeParamName = $this->resolveScopeRelativeParamName($paramName, $namespace, $group->getName());
42
            if ($this->container->hasParameter($groupScopeParamName)) {
43
                return $this->container->getParameter($groupScopeParamName);
44
            }
45
46
            $triedScopes[] = $group->getName();
47
        }
48
49
        throw new ParameterNotFoundException($paramName, $namespace, $triedScopes);
50
    }
51
}
52