AuthRequest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 161
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 4

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrlPath() 0 4 1
A isPost() 0 4 1
A getPostData() 0 17 2
A getAuthToken() 0 4 1
A setAuthToken() 0 6 1
A getChannels() 0 4 1
A setChannels() 0 6 1
A getExpireTime() 0 4 1
A setExpireTime() 0 6 1
A isPrivate() 0 4 1
A setPrivate() 0 6 1
A getResponseHandler() 0 4 1
1
<?php
2
3
namespace ninjacto\OrtcPhp\Models\Requests;
4
5
use ninjacto\OrtcPhp\Handlers\AuthResponseHandler;
6
use ninjacto\OrtcPhp\Handlers\OrtcResponseHandler;
7
use ninjacto\OrtcPhp\Models\Channel;
8
9
class AuthRequest extends OrtcRequest
10
{
11
    /**
12
     * channels.
13
     *
14
     * @var Channel[]
15
     */
16
    private $channels;
17
18
    /**
19
     * authentication token.
20
     *
21
     * @var string
22
     */
23
    private $authToken;
24
25
    /**
26
     * expiration time (ttl) in seconds.
27
     *
28
     * @var int
29
     */
30
    private $expireTime;
31
32
    /**
33
     * @var bool
34
     */
35
    private $private = false;
36
37
    /**
38
     * get url path (not base url).
39
     *
40
     * @return string
41
     */
42 1
    public function getUrlPath()
43
    {
44 1
        return $this->getOrtcConfig()->getAuthenticationPath();
45
    }
46
47
    /**
48
     * is post request or get request?
49
     *
50
     * @return bool
51
     */
52 1
    public function isPost()
53
    {
54 1
        return true;
55
    }
56
57
    /**
58
     * get post body.
59
     *
60
     * @return array
61
     */
62 1
    public function getPostData()
63
    {
64
        $postData = [
65 1
            'AT'  => $this->getAuthToken(),
66 1
            'PVT' => intval($this->isPrivate()),
67 1
            'AK'  => $this->getOrtcConfig()->getApplicationKey(),
68 1
            'TTL' => $this->getExpireTime(),
69 1
            'PK'  => $this->getOrtcConfig()->getPrivateKey(),
70 1
            'TP'  => count($this->getChannels()),
71 1
        ];
72
73 1
        foreach ($this->getChannels() as $channel) {
74 1
            $postData[$channel->getName()] = $channel->getPermission();
75 1
        }
76
77 1
        return $postData;
78
    }
79
80
    /**
81
     * @return string
82
     */
83 2
    public function getAuthToken()
84
    {
85 2
        return $this->authToken;
86
    }
87
88
    /**
89
     * @param string $authToken
90
     *
91
     * @return $this
92
     */
93 2
    public function setAuthToken($authToken)
94
    {
95 2
        $this->authToken = $authToken;
96
97 2
        return $this;
98
    }
99
100
    /**
101
     * @return \ninjacto\OrtcPhp\Models\Channel[]
102
     */
103 2
    public function getChannels()
104
    {
105 2
        return $this->channels;
106
    }
107
108
    /**
109
     * @param \ninjacto\OrtcPhp\Models\Channel[] $channels
110
     *
111
     * @return $this
112
     */
113 2
    public function setChannels($channels)
114
    {
115 2
        $this->channels = $channels;
116
117 2
        return $this;
118
    }
119
120
    /**
121
     * @return int
122
     */
123 2
    public function getExpireTime()
124
    {
125 2
        return $this->expireTime;
126
    }
127
128
    /**
129
     * @param int $expireTime
130
     *
131
     * @return $this
132
     */
133 2
    public function setExpireTime($expireTime)
134
    {
135 2
        $this->expireTime = $expireTime;
136
137 2
        return $this;
138
    }
139
140
    /**
141
     * @return bool
142
     */
143 2
    public function isPrivate()
144
    {
145 2
        return $this->private;
146
    }
147
148
    /**
149
     * @param bool $private
150
     *
151
     * @return $this
152
     */
153 1
    public function setPrivate($private)
154
    {
155 1
        $this->private = (bool) $private;
156
157 1
        return $this;
158
    }
159
160
    /**
161
     * get response handler.
162
     *
163
     * @return OrtcResponseHandler
164
     */
165 1
    public function getResponseHandler()
166
    {
167 1
        return new AuthResponseHandler();
168
    }
169
}
170