NestedTokenLoaderAbstractFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 17
c 1
b 0
f 0
dl 0
loc 44
ccs 14
cts 16
cp 0.875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceTypeName() 0 3 1
A __invoke() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\JWTModule\DIFactory\NestedToken;
6
7
use Interop\Container\ContainerInterface;
8
use Interop\Container\Exception\ContainerException;
9
use Jose\Component\NestedToken\NestedTokenLoader;
10
use Jose\Component\NestedToken\NestedTokenLoaderFactory;
11
use TMV\JWTModule\DIFactory\AbstractServiceFactory;
12
use TMV\JWTModule\Exception\InvalidArgumentException;
13
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
14
use Zend\ServiceManager\Exception\ServiceNotFoundException;
15
16
class NestedTokenLoaderAbstractFactory extends AbstractServiceFactory
17
{
18
    private const SERVICE_TYPE_KEY = 'nested_token_loader';
19
20
    /**
21
     * Create an object
22
     *
23
     * @param ContainerInterface $container
24
     * @param string $requestedName
25
     * @param null|array $options
26
     *
27
     * @throws ServiceNotFoundException if unable to resolve the service
28
     * @throws ServiceNotCreatedException if an exception is raised when
29
     *     creating a service
30
     * @throws ContainerException if any other error occurs
31
     *
32
     * @return NestedTokenLoader
33
     */
34 2
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): NestedTokenLoader
35
    {
36
        try {
37 2
            $keyConfig = $this->getServiceConfig($container, $requestedName);
38
        } catch (InvalidArgumentException $e) {
39
            throw new ServiceNotCreatedException('Unable to find service for ' . $requestedName);
40
        }
41
42
        /** @var NestedTokenLoaderFactory $factory */
43 2
        $factory = $container->get(NestedTokenLoaderFactory::class);
44
45 2
        return $factory->create(
46 2
            $keyConfig['jwe_serializers'] ?? [],
47 2
            $keyConfig['key_encryption_algorithms'] ?? [],
48 2
            $keyConfig['content_encryption_algorithms'] ?? [],
49 2
            $keyConfig['compression_methods'] ?? [],
50 2
            $keyConfig['jwe_header_checkers'] ?? [],
51 2
            $keyConfig['jws_serializers'] ?? [],
52 2
            $keyConfig['signature_algorithms'] ?? [],
53 2
            $keyConfig['jws_header_checkers'] ?? []
54
        );
55
    }
56
57 3
    protected function getServiceTypeName(): string
58
    {
59 3
        return static::SERVICE_TYPE_KEY;
60
    }
61
}
62