Request::getToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Source\Core;
4
5
final class Request
6
{
7
    private $error;
8
9
    public function getRequestHeader(string $headerParam)
10
    {
11
        $headers = getallheaders();
12
13
        if ($headerParam == 'all') {
14
            return $headers;
15
        }
16
17
        return isset($headers[$headerParam]) ? [$headerParam => $headers[$headerParam]] : false;
18
    }
19
20
    public function getToken()
21
    {
22
        if (!($token = $this->getRequestHeader('authorization'))) {
23
            $this->error = "require login";
24
            return false;
25
        }
26
27
        $token = str_replace(['Bearer', ' '], '', $token['authorization']);
28
29
        return $token;
30
    }
31
32
    public function getError()
33
    {
34
        return $this->error;
35
    }
36
}
37