ClaimCheckerManagerAbstractFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
ccs 5
cts 7
cp 0.7143
rs 10
cc 2
nc 2
nop 3
crap 2.0932
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\JWTModule\DIFactory\Checker;
6
7
use Interop\Container\ContainerInterface;
8
use Jose\Component\Checker\ClaimCheckerManager;
9
use Jose\Component\Checker\ClaimCheckerManagerFactory;
10
use TMV\JWTModule\DIFactory\AbstractServiceFactory;
11
use TMV\JWTModule\Exception\InvalidArgumentException;
12
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
13
use Zend\ServiceManager\Exception\ServiceNotFoundException;
14
15
class ClaimCheckerManagerAbstractFactory extends AbstractServiceFactory
16
{
17
    private const SERVICE_TYPE_KEY = 'claim_checker';
18
19
    /**
20
     * Create an object
21
     *
22
     * @param ContainerInterface $container
23
     * @param string $requestedName
24
     * @param null|array $options
25
     *
26
     * @throws ServiceNotFoundException if unable to resolve the service
27
     * @throws ServiceNotCreatedException if an exception is raised when
28
     *     creating a service
29
     *
30
     * @return ClaimCheckerManager
31
     */
32 2
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ClaimCheckerManager
33
    {
34
        try {
35 2
            $keyConfig = $this->getServiceConfig($container, $requestedName);
36
        } catch (InvalidArgumentException $e) {
37
            throw new ServiceNotCreatedException('Unable to find service for ' . $requestedName);
38
        }
39
40 2
        $claims = $keyConfig['claims'] ?? [];
41
42
        /** @var ClaimCheckerManagerFactory $factory */
43 2
        $factory = $container->get(ClaimCheckerManagerFactory::class);
44
45 2
        return $factory->create($claims);
46
    }
47
48 14
    protected function getServiceTypeName(): string
49
    {
50 14
        return static::SERVICE_TYPE_KEY;
51
    }
52
}
53