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.
Passed
Pull Request — master (#160)
by
unknown
03:14
created

HttpDataCollector::getSymfonyVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace EightPoints\Bundle\GuzzleBundle\DataCollector;
4
5
use EightPoints\Bundle\GuzzleBundle\Log\LogGroup;
6
use EightPoints\Bundle\GuzzleBundle\Log\LoggerInterface;
7
use EightPoints\Bundle\GuzzleBundle\Log\LogMessage;
8
use Psr\Log\LogLevel;
9
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpKernel\Kernel;
13
14
/**
15
 * Collecting http data for Symfony profiler
16
 */
17
class HttpDataCollector extends DataCollector
18
{
19
    /** @var \EightPoints\Bundle\GuzzleBundle\Log\LoggerInterface */
20
    protected $logger;
21
22
    /**
23
     * @param \EightPoints\Bundle\GuzzleBundle\Log\LoggerInterface $logger
24
     */
25
    public function __construct(LoggerInterface $logger)
26
    {
27
        $this->logger = $logger;
28
29
        $this->reset();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function collect(Request $request, Response $response, \Exception $exception = null)
36
    {
37
        $messages = $this->logger->getMessages();
38
        $requestId = $request->getUri();
39
40
        // clear log to have only messages related to Symfony request context
41
        $this->logger->clear();
42
43
        $logGroup = $this->getLogGroup($requestId);
44
        $logGroup->setRequestName($request->getPathInfo());
45
        $logGroup->addMessages($messages);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getName() : string
52
    {
53
        return 'eight_points_guzzle';
54
    }
55
56
    /**
57
     * Resets this data collector to its initial state.
58
     *
59
     * @return void
60
     */
61
    public function reset()
62
    {
63
        $this->data = [
64
            'logs' => [],
65
            'callCount' => 0,
66
            'totalTime' => 0,
67
        ];
68
    }
69
70
    /**
71
     * Returning log entries
72
     *
73
     * @return array
74
     */
75
    public function getLogs() : array
76
    {
77
        return array_key_exists('logs', $this->data) ? $this->data['logs'] : [];
78
    }
79
80
    /**
81
     * Get all messages
82
     *
83
     * @return array
84
     */
85
    public function getMessages() : array
86
    {
87
        $messages = [];
88
89
        foreach ($this->getLogs() as $log) {
90
            foreach ($log->getMessages() as $message) {
91
                $messages[] = $message;
92
            }
93
        }
94
95
        return $messages;
96
    }
97
98
    /**
99
     * Return amount of http calls
100
     *
101
     * @return integer
102
     */
103
    public function getCallCount() : int
104
    {
105
        return count($this->getMessages());
106
    }
107
108
    /**
109
     * Get Error Count
110
     *
111
     * @return integer
112
     */
113
    public function getErrorCount() : int
114
    {
115
        return count(array_filter($this->getMessages(), function (LogMessage $message) {
116
            return $message->getLevel() === LogLevel::ERROR;
117
        }));
118
    }
119
120
    /**
121
     * Get total time of all requests
122
     *
123
     * @return float
124
     */
125
    public function getTotalTime() : float
126
    {
127
        return $this->data['totalTime'];
128
    }
129
130
    /**
131
     * @param float $time
132
     *
133
     * @return void
134
     */
135
    public function addTotalTime(float $time)
136
    {
137
        $this->data['totalTime'] += $time;
138
    }
139
140
    /**
141
     * Returns (new) LogGroup based on given id
142
     *
143
     * @param string $id
144
     *
145
     * @return \EightPoints\Bundle\GuzzleBundle\Log\LogGroup
146
     */
147
    protected function getLogGroup(string $id) : LogGroup
148
    {
149
        if (!isset($this->data['logs'][$id])) {
150
            $this->data['logs'][$id] = new LogGroup();
151
        }
152
153
        return $this->data['logs'][$id];
154
    }
155
156
    /**
157
     * Return the color used version
158
     *
159
     * @return string
160
     */
161
    public final function getIconColor() : string
162
    {
163
        if (version_compare(Kernel::VERSION, '2.8.0', '>=')) {
164
            return $this->data['iconColor'] = '#AAAAAA';
165
        }
166
167
        return $this->data['iconColor'] = '#3F3F3F';
168
    }
169
}
170