Completed
Push — dynamic_siteaccesses ( 16c7ff )
by
unknown
20:23
created

SiteAccessGroupConfigResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doHasParameter() 0 11 3
A doGetParameter() 0 15 3
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
class SiteAccessGroupConfigResolver extends SiteAccessBasedConfigResolver
16
{
17
    use ContainerAwareTrait;
18
19
    protected function doHasParameter(SiteAccess $siteAccess, string $paramName, string $namespace): bool
20
    {
21
        foreach ($siteAccess->groups as $group) {
22
            $groupScopeParamName = $this->resolveScopeRelativeParamName($paramName, $namespace, $group->getName());
23
            if ($this->container->hasParameter($groupScopeParamName)) {
24
                return true;
25
            }
26
        }
27
28
        return false;
29
    }
30
31
    protected function doGetParameter(SiteAccess $siteAccess, string $paramName, string $namespace)
32
    {
33
        $triedScopes = [];
34
35
        foreach ($siteAccess->groups as $group) {
36
            $groupScopeParamName = $this->resolveScopeRelativeParamName($paramName, $namespace, $group->getName());
37
            if ($this->container->hasParameter($groupScopeParamName)) {
38
                return $this->container->getParameter($groupScopeParamName);
39
            }
40
41
            $triedScopes[] = $group->getName();
42
        }
43
44
        throw new ParameterNotFoundException($paramName, $namespace, $triedScopes);
45
    }
46
}
47