GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Logger::addTransferTimeByRequestId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EightPoints\Bundle\GuzzleBundle\Log;
4
5
use Namshi\Cuzzle\Formatter\CurlFormatter;
0 ignored issues
show
Bug introduced by
The type Namshi\Cuzzle\Formatter\CurlFormatter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Psr\Log\LoggerTrait;
7
8
class Logger implements LoggerInterface
9
{
10
    const LOG_MODE_NONE = 0;
11
    const LOG_MODE_REQUEST = 1;
12
    const LOG_MODE_REQUEST_AND_RESPONSE_HEADERS = 2;
13
    const LOG_MODE_REQUEST_AND_RESPONSE = 3;
14
15
    use LoggerTrait;
16
17
    /** @var \EightPoints\Bundle\GuzzleBundle\Log\LogMessage[] */
18
    private $messages = [];
19
20
    /** @var int */
21
    private $logMode;
22
23
    public function __construct(int $logMode = self::LOG_MODE_REQUEST_AND_RESPONSE)
24
    {
25
        $this->logMode = $logMode;
26
    }
27
28
    /**
29
     * Log message
30
     *
31
     * @param string $level
32
     * @param string $message
33
     * @param array  $context
34
     *
35
     * @return void
36
     */
37
    public function log($level, $message, array $context = [])
38
    {
39
        $requestId = isset($context['requestId']) ? $context['requestId'] : uniqid('eight_points_guzzle_');
40
41
        if (array_key_exists($requestId, $this->messages)) {
42
            $logMessage = $this->messages[$requestId];
43
        } else {
44
            $logMessage = new LogMessage($message);
45
        }
46
47
        $logMessage->setLevel($level);
48
49
        if (!empty($context)) {
50
            if (!empty($context['request']) && $this->logMode > self::LOG_MODE_NONE) {
51
                $logMessage->setRequest(new LogRequest($context['request']));
52
53
                if (class_exists(CurlFormatter::class)) {
54
                    $logMessage->setCurlCommand((new CurlFormatter())->format($context['request']));
55
                }
56
            }
57
58
            if (!empty($context['response']) && $this->logMode > self::LOG_MODE_REQUEST) {
59
                $logMessage->setResponse(new LogResponse(
60
                    $context['response'],
61
                    $this->logMode > self::LOG_MODE_REQUEST_AND_RESPONSE_HEADERS
62
                ));
63
            }
64
        }
65
66
        $this->messages[$requestId] = $logMessage;
67
    }
68
69
    /**
70
     * Clear messages list
71
     *
72
     * @return void
73
     */
74
    public function clear() : void
75
    {
76
        $this->messages = [];
77
    }
78
79
    /**
80
     * Return if messages exist or not
81
     *
82
     * @return boolean
83
     */
84
    public function hasMessages() : bool
85
    {
86
        return $this->getMessages() ? true : false;
87
    }
88
89
    /**
90
     * Return log messages
91
     *
92
     * @return \EightPoints\Bundle\GuzzleBundle\Log\LogMessage[]
93
     */
94
    public function getMessages() : array
95
    {
96
        return $this->messages;
97
    }
98
99
    /**
100
     * @param string|null $requestId
101
     * @param float $transferTime
102
     *
103
     * @return void
104
     */
105
    public function addTransferTimeByRequestId(?string $requestId, float $transferTime) : void
106
    {
107
        if (array_key_exists($requestId, $this->messages)) {
108
            $this->messages[$requestId]->setTransferTime($transferTime);
109
        }
110
    }
111
}
112