Completed
Push — master ( fec6f1...fc6f01 )
by Alexandre
03:31
created

StorageRepositoryBuilder::build()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 0
dl 0
loc 24
rs 8.9137
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 23/06/2018
6
 * Time: 18:36
7
 */
8
9
namespace OAuth2\Storages;
10
11
12
class StorageRepositoryBuilder
13
{
14
    /**
15
     * @var ClientStorageInterface|null
16
     */
17
    private $clientStorage;
18
    /**
19
     * @var ResourceOwnerStorageInterface|null
20
     */
21
    private $resourceOwnerStorage;
22
    /**
23
     * @var AuthorizationCodeStorageInterface|null
24
     */
25
    private $authorizationCodeStorage;
26
    /**
27
     * @var AccessTokenStorageInterface|null
28
     */
29
    private $accessTokenStorage;
30
    /**
31
     * @var RefreshTokenStorageInterface|null
32
     */
33
    private $refreshTokenStorage;
34
35
    /**
36
     * @return StorageManager
37
     */
38
    public function build(): StorageManager
39
    {
40
        if(!$this->clientStorage) {
41
            throw new \InvalidArgumentException('Client storage is missing');
42
        }
43
        if(!$this->resourceOwnerStorage) {
44
            throw new \InvalidArgumentException('Resource owner storage is missing');
45
        }
46
        if(!$this->authorizationCodeStorage) {
47
            throw new \InvalidArgumentException('Authorization code storage is missing');
48
        }
49
        if(!$this->accessTokenStorage) {
50
            throw new \InvalidArgumentException('Access token storage is missing');
51
        }
52
        if(!$this->refreshTokenStorage) {
53
            throw new \InvalidArgumentException('Refresh token storage is missing');
54
        }
55
56
        return new StorageManager(
57
            $this->clientStorage,
58
            $this->resourceOwnerStorage,
59
            $this->authorizationCodeStorage,
60
            $this->accessTokenStorage,
61
            $this->refreshTokenStorage
62
        );
63
    }
64
65
    /**
66
     * @param ClientStorageInterface $clientStorage
67
     * @return StorageRepositoryBuilder
68
     */
69
    public function setClientStorage(ClientStorageInterface $clientStorage): self
70
    {
71
        $this->clientStorage = $clientStorage;
72
        return $this;
73
    }
74
75
    /**
76
     * @param ResourceOwnerStorageInterface $resourceOwnerStorage
77
     * @return StorageRepositoryBuilder
78
     */
79
    public function setResourceOwnerStorage(ResourceOwnerStorageInterface $resourceOwnerStorage): self
80
    {
81
        $this->resourceOwnerStorage = $resourceOwnerStorage;
82
        return $this;
83
    }
84
85
    /**
86
     * @param AuthorizationCodeStorageInterface $authorizationCodeStorage
87
     * @return StorageRepositoryBuilder
88
     */
89
    public function setAuthorizationCodeStorage(AuthorizationCodeStorageInterface $authorizationCodeStorage): self
90
    {
91
        $this->authorizationCodeStorage = $authorizationCodeStorage;
92
        return $this;
93
    }
94
95
    /**
96
     * @param AccessTokenStorageInterface $accessTokenStorage
97
     * @return StorageRepositoryBuilder
98
     */
99
    public function setAccessTokenStorage(AccessTokenStorageInterface $accessTokenStorage): self
100
    {
101
        $this->accessTokenStorage = $accessTokenStorage;
102
        return $this;
103
    }
104
105
    /**
106
     * @param RefreshTokenStorageInterface $refreshTokenStorage
107
     * @return StorageRepositoryBuilder
108
     */
109
    public function setRefreshTokenStorage(RefreshTokenStorageInterface $refreshTokenStorage): self
110
    {
111
        $this->refreshTokenStorage = $refreshTokenStorage;
112
        return $this;
113
    }
114
}