Request   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 3 1
A getRequestHeader() 0 9 3
A getToken() 0 10 2
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