AccessLog::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Previewtechs\HTTP\AccessLogger;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Psr\Log\LoggerInterface;
7
8
/**
9
 * Class AccessLog
10
 * @package Previewtechs\HTTP\AccessLogger
11
 */
12
class AccessLog extends AbstractProvider
13
{
14
    /**
15
     * @var StorageInterface
16
     */
17
    protected $storage;
18
19
    /**
20
     * @var ServerRequestInterface
21
     */
22
    public $request;
23
24
    /**
25
     * @var array
26
     */
27
    public $data = [];
28
29
    /**
30
     * @var LoggerInterface $logger
31
     */
32
    public $logger;
33
34
    /**
35
     * AccessLog constructor.
36
     * @param ServerRequestInterface $request
37
     * @param StorageInterface $storage
38
     */
39 5
    public function __construct(ServerRequestInterface $request, StorageInterface $storage)
40
    {
41 5
        $this->storage = $storage;
42 5
        $this->request = $request;
43
44 5
        $this->data = parent::getData();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getData() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->getData().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
45 5
    }
46
47
    /**
48
     * @param LoggerInterface $logger
49
     */
50 1
    public function setLogger(LoggerInterface $logger)
51
    {
52 1
        $this->logger = $logger;
53 1
    }
54
55
    /**
56
     * @return array
57
     */
58 2
    public function getData()
59
    {
60 2
        return $this->data;
61
    }
62
63
    /**
64
     * @param $key
65
     * @param $value
66
     * @return $this
67
     */
68 1
    public function add($key, $value)
69
    {
70 1
        $this->data[$key] = $value;
71 1
        return $this;
72
    }
73
74
    /**
75
     * @return mixed
76
     */
77 1
    public function record()
78
    {
79
        try {
80 1
            return $this->storage->save($this->data);
81
            // @codeCoverageIgnoreStart
82
        } catch (\Exception $exception) {
83
            $this->logger ? $this->logger->error($exception->getMessage()) : false;
84
            $this->logger ? $this->logger->debug($exception->getTraceAsString()) : false;
85
86
            return false;
87
        }
88
            // @codeCoverageIgnoreStart
89
    }
90
}
91