Failed Conditions
Push — v7 ( 838dcb )
by Florent
04:30
created

JWAManager::removeAlgorithm()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 5
nop 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Algorithm;
13
14
/**
15
 * Class JWAManager.
16
 */
17
final class JWAManager
18
{
19
    /**
20
     * @var array
21
     */
22
    private $algorithms = [];
23
24
    /**
25
     * @param string $algorithm
26
     *
27
     * @return bool
28
     */
29
    public function isAlgorithmSupported(string $algorithm): bool
30
    {
31
        return null !== $this->getAlgorithm($algorithm);
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    public function getAlgorithms(): array
38
    {
39
        return $this->algorithms;
40
    }
41
42
    /**
43
     * @return string[]
44
     */
45
    public function listAlgorithms(): array
46
    {
47
        return array_keys($this->getAlgorithms());
48
    }
49
50
    /**
51
     * @param string $algorithm
52
     * @return JWAInterface|null
53
     */
54
    public function getAlgorithm(string $algorithm): ?JWAInterface
55
    {
56
        return array_key_exists($algorithm, $this->algorithms) ? $this->algorithms[$algorithm] : null;
57
    }
58
59
    /**
60
     * @param JWAInterface $algorithm
61
     */
62
    public function addAlgorithm(JWAInterface $algorithm)
63
    {
64
        if (!$this->isAlgorithmSupported($algorithm->getAlgorithmName())) {
65
            $this->algorithms[$algorithm->getAlgorithmName()] = $algorithm;
66
        }
67
    }
68
}
69