Failed Conditions
Push — master ( 7f2d83...323120 )
by Florent
05:07
created

ResponseTypeManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A has() 0 4 1
A get() 0 8 2
A list() 0 4 1
A all() 0 4 1
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\ResponseType;
15
16
class ResponseTypeManager
17
{
18
    /**
19
     * @var ResponseType[]
20
     */
21
    private $responseTypes = [];
22
23
    public function add(ResponseType $responseType): void
24
    {
25
        $this->responseTypes[$responseType->name()] = $responseType;
26
    }
27
28
    public function has(string $responseType): bool
29
    {
30
        return \array_key_exists($responseType, $this->responseTypes);
31
    }
32
33
    public function get(string $responseType): ResponseType
34
    {
35
        if (!$this->has($responseType)) {
36
            throw new \InvalidArgumentException(\sprintf('The response type "%s" is not supported.', $responseType));
37
        }
38
39
        return $this->responseTypes[$responseType];
40
    }
41
42
    /**
43
     * @return string[]
44
     */
45
    public function list(): array
46
    {
47
        return \array_keys($this->responseTypes);
48
    }
49
50
    /**
51
     * @return ResponseType[]
52
     */
53
    public function all(): array
54
    {
55
        return \array_values($this->responseTypes);
56
    }
57
}
58