Passed
Pull Request — master (#5753)
by Angel Fernando Quiroz
08:44
created

AuthenticationConfigHelper::__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 InvalidArgumentException;
11
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
12
13
readonly class AuthenticationConfigHelper
14
{
15
    public function __construct(
16
        private ParameterBagInterface $parameterBag,
17
        private AccessUrlHelper $urlHelper,
18
    ) {}
19
20
    public function getParams(string $providerName, ?AccessUrl $url = null): array
21
    {
22
        $urlId = $url ? $url->getId() : $this->urlHelper->getCurrent()->getId();
23
24
        $authentication = $this->parameterBag->get('authentication');
25
26
        if (!isset($authentication[$urlId])) {
27
            throw new InvalidArgumentException('Invalid access URL Id');
28
        }
29
30
        if (!isset($authentication[$urlId][$providerName])) {
31
            throw new InvalidArgumentException('Invalid authentication source');
32
        }
33
34
        return $authentication[$urlId][$providerName];
35
    }
36
37
    public function isEnabled(string $methodName, ?AccessUrl $url = null): bool
38
    {
39
        $configParams = $this->getParams($methodName, $url);
40
41
        return $configParams['enabled'] ?? false;
42
    }
43
}
44