FlowManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addFlow() 0 13 3
A getFlow() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 18/02/2018
6
 * Time: 18:57
7
 */
8
9
namespace OAuth2\AuthorizationGrantTypes\Flows;
10
11
12
use OAuth2\AuthorizationGrantTypes\GrantTypeManager;
13
use OAuth2\AuthorizationEndpointResponseTypes\ResponseTypeManager;
14
15
class FlowManager
16
{
17
    protected $flows = [];
18
    /**
19
     * @var ResponseTypeManager
20
     */
21
    private $responseTypeManager;
22
    /**
23
     * @var GrantTypeManager
24
     */
25
    private $grantTypeManager;
26
27
    public function __construct(ResponseTypeManager $responseTypeManager, GrantTypeManager $grantTypeManager)
28
    {
29
        $this->responseTypeManager = $responseTypeManager;
30
        $this->grantTypeManager = $grantTypeManager;
31
    }
32
33
    public function addFlow(string $identifier, FlowInterface $flow): self
34
    {
35
        $this->flows[$identifier] = $flow;
36
37
        foreach ($flow->getResponseTypes() as $responseType) {
38
            $this->responseTypeManager->setResponseType($responseType, $flow);
39
        }
40
41
        foreach ($flow->getGrantTypes() as $grantType) {
42
            $this->grantTypeManager->setGrantType($grantType, $flow);
43
        }
44
45
        return $this;
46
    }
47
48
    public function getFlow(string $identifier): ?FlowInterface
49
    {
50
        return $this->flows[$identifier] ?? null;
51
    }
52
}