Passed
Push — master ( 6761c6...82c8fb )
by Angel Fernando Quiroz
08:20 queued 13s
created

SettingsManagerHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\ServiceHelper;
8
9
use Chamilo\CoreBundle\Entity\AccessUrl;
10
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
11
12
readonly class SettingsManagerHelper
13
{
14
    public function __construct(
15
        private ParameterBagInterface $parameterBag,
16
        private AccessUrlHelper $accessUrlHelper,
17
    ) {}
18
19
    public function isOverridden(string $name, ?AccessUrl $accessUrl = null): bool
20
    {
21
        return null !== $this->getOverride($name, $accessUrl);
22
    }
23
24
    public function getOverride(string $name, ?AccessUrl $accessUrl = null): mixed
25
    {
26
        if (!$this->parameterBag->has('settings_overrides')) {
27
            return null;
28
        }
29
30
        $settingsOverrides = $this->parameterBag->get('settings_overrides');
31
32
        $accessUrl ??= $this->accessUrlHelper->getCurrent();
33
34
        if (isset($settingsOverrides[$accessUrl->getId()][$name])) {
0 ignored issues
show
Bug introduced by
The method getId() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        if (isset($settingsOverrides[$accessUrl->/** @scrutinizer ignore-call */ getId()][$name])) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
            return $settingsOverrides[$accessUrl->getId()][$name];
36
        }
37
38
        if (isset($settingsOverrides['default'][$name])) {
39
            return $settingsOverrides['default'][$name];
40
        }
41
42
        return null;
43
    }
44
}