Failed Conditions
Push — ng ( f68947...95ea19 )
by Florent
04:36
created

ResponseModeManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 61
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 4 1
A all() 0 4 1
A add() 0 6 1
A has() 0 4 1
A get() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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 OAuth2Framework\Component\AuthorizationEndpoint\ResponseMode;
15
16
class ResponseModeManager
17
{
18
    /**
19
     * @var ResponseMode[]
20
     */
21
    private $responseModes = [];
22
23
    /**
24
     * @return string[]
25
     */
26
    public function list(): array
27
    {
28
        return array_keys($this->responseModes);
29
    }
30
31
    /**
32
     * @return string[]
33
     */
34
    public function all(): array
35
    {
36
        return array_values($this->responseModes);
37
    }
38
39
    /**
40
     * @param ResponseMode $responseMode
41
     *
42
     * @return ResponseModeManager
43
     */
44
    public function add(ResponseMode $responseMode)
45
    {
46
        $this->responseModes[$responseMode->name()] = $responseMode;
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param string $name
53
     *
54
     * @return bool
55
     */
56
    public function has(string $name): bool
57
    {
58
        return array_key_exists($name, $this->responseModes);
59
    }
60
61
    /**
62
     * @param string $name
63
     *
64
     * @throws \InvalidArgumentException
65
     *
66
     * @return ResponseMode
67
     */
68
    public function get(string $name): ResponseMode
69
    {
70
        if (!$this->has($name)) {
71
            throw new \InvalidArgumentException(sprintf('The response mode with name "%s" is not supported.', $name));
72
        }
73
74
        return $this->responseModes[$name];
75
    }
76
}
77