Failed Conditions
Pull Request — master (#37)
by Florent
15:49 queued 11:56
created

ResponseModeManager::getSupportedResponseModes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 OAuth2Framework\Component\Server\ResponseMode;
15
16
use Assert\Assertion;
17
18
final class ResponseModeManager
19
{
20
    /**
21
     * @var ResponseModeInterface[]
22
     */
23
    private $responseModes = [];
24
25
    /**
26
     * @return string[]
27
     */
28
    public function all(): array
29
    {
30
        return array_keys($this->responseModes);
31
    }
32
33
    /**
34
     * @param ResponseModeInterface $responseMode
35
     *
36
     * @return ResponseModeManager
37
     */
38
    public function add(ResponseModeInterface $responseMode)
39
    {
40
        $this->responseModes[$responseMode->name()] = $responseMode;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @param string $name
47
     *
48
     * @return bool
49
     */
50
    public function has(string $name): bool
51
    {
52
        return array_key_exists($name, $this->responseModes);
53
    }
54
55
    /**
56
     * @param string $name
57
     *
58
     * @throws \InvalidArgumentException
59
     *
60
     * @return ResponseModeInterface
61
     */
62
    public function get(string $name): ResponseModeInterface
63
    {
64
        Assertion::true($this->has($name), sprintf('The response mode with name \'%s\' is not supported.', $name));
65
66
        return $this->responseModes[$name];
67
    }
68
69
    /**
70
     * @return string[]
71
     */
72
    public function list(): array
73
    {
74
        return array_keys($this->responseModes);
75
    }
76
}
77