AbstractProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 62
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getIP() 0 4 1
A getEndpoint() 0 4 1
A getMethod() 0 4 1
A getVersion() 0 5 1
A getCreated() 0 4 1
A getData() 0 10 1
1
<?php
2
3
namespace Previewtechs\HTTP\AccessLogger;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class AbstractProvider
9
 * @package Previewtechs\API\AccessLogger
10
 */
11
abstract class AbstractProvider
12
{
13
    /**
14
     * @var ServerRequestInterface
15
     */
16
    public $request;
17
18
    /**
19
     * @return string
20
     */
21 5
    public function getIP()
22
    {
23 5
        return $this->request->getServerParams()['REMOTE_ADDR'];
24
    }
25
26
    /**
27
     * @return string
28
     */
29 5
    public function getEndpoint()
30
    {
31 5
        return $this->request->getUri()->getPath();
32
    }
33
34
    /**
35
     * @return string
36
     */
37 5
    public function getMethod()
38
    {
39 5
        return $this->request->getMethod();
40
    }
41
42
    /**
43
     * @return string|null
44
     */
45 5
    public function getVersion()
46
    {
47 5
        preg_match("/\/v[0-9]\//", $this->request->getUri()->getPath(), $match);
48 5
        return str_replace('/', '', $match[0]);
49
    }
50
51
    /**
52
     * @return \DateTime
53
     */
54 5
    public function getCreated()
55
    {
56 5
        return new \DateTime('now');
57
    }
58
59
    /**
60
     * @return array
61
     */
62 5
    public function getData()
63
    {
64
        return [
65 5
            'method' => $this->getMethod(),
66 5
            'endpoint' => $this->getEndpoint(),
67 5
            'version' => $this->getVersion(),
68 5
            'request_ip' => $this->getIP(),
69 5
            'created' => $this->getCreated()
70 5
        ];
71
    }
72
}
73