Failed Conditions
Push — v7 ( c80b33...0b1ec1 )
by Florent
04:39
created

JWAManagerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A create() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Core;
15
16
final class JWAManagerFactory
17
{
18
    /**
19
     * @var array
20
     */
21
    private $algorithms;
22
23
    /**
24
     * @param string $alias
25
     * @param JWAInterface $algorithm
26
     */
27
    public function add(string $alias, JWAInterface $algorithm)
28
    {
29
        $this->algorithms[$alias] = $algorithm;
30
    }
31
32
    /**
33
     * @param string[] $aliases
34
     *
35
     * @return JWAManager
36
     */
37
    public function create(array $aliases): JWAManager
38
    {
39
        $algorithms = [];
40
        foreach ($aliases as $alias) {
41
            if (array_key_exists($alias, $this->algorithms)) {
42
                $algorithms[] = $this->algorithms[$alias];
43
            } else {
44
                throw new \InvalidArgumentException(sprintf('The algorithm with the alias "%s" is not supported.', $alias));
45
            }
46
        }
47
48
        return JWAManager::create($algorithms);
49
    }
50
}
51