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.

LogMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A log() 0 38 2
1
<?php
2
3
namespace EightPoints\Bundle\GuzzleBundle\Middleware;
4
5
use GuzzleHttp\Exception\RequestException;
6
use GuzzleHttp\MessageFormatter;
7
use EightPoints\Bundle\GuzzleBundle\Log\LoggerInterface;
8
9
class LogMiddleware
10
{
11
    /** @var \GuzzleHttp\MessageFormatter */
12
    protected $formatter;
13
14
    /** @var \EightPoints\Bundle\GuzzleBundle\Log\LoggerInterface */
15
    protected $logger;
16
17
    /**
18
     * @param \EightPoints\Bundle\GuzzleBundle\Log\LoggerInterface $logger
19
     * @param \GuzzleHttp\MessageFormatter $formatter
20
     */
21
    public function __construct(LoggerInterface $logger, MessageFormatter $formatter)
22
    {
23
        $this->logger    = $logger;
24
        $this->formatter = $formatter;
25
    }
26
27
    /**
28
     * Logging each Request
29
     *
30
     * @return \Closure
31
     */
32
    public function log() : \Closure
33
    {
34
        $logger    = $this->logger;
35
        $formatter = $this->formatter;
36
37
        return function (callable $handler) use ($logger, $formatter) {
38
39
            return function ($request, array $options) use ($handler, $logger, $formatter) {
40
                // generate id that will be used to supplement the log with information
41
                $requestId = uniqid('eight_points_guzzle_');
42
43
                // initial registration of log
44
                $logger->info('', compact('request', 'requestId'));
45
46
                // this id will be used by RequestTimeMiddleware
47
                $options['request_id'] = $requestId;
48
49
                return $handler($request, $options)->then(
50
51
                    function ($response) use ($logger, $request, $formatter, $requestId) {
52
53
                        $message = $formatter->format($request, $response);
54
                        $context = compact('request', 'response', 'requestId');
55
56
                        $logger->info($message, $context);
57
58
                        return $response;
59
                    },
60
61
                    function ($reason) use ($logger, $request, $formatter, $requestId) {
62
63
                        $response = $reason instanceof RequestException ? $reason->getResponse() : null;
64
                        $message  = $formatter->format($request, $response, $reason);
65
                        $context  = compact('request', 'response', 'requestId');
66
67
                        $logger->notice($message, $context);
68
69
                        return \GuzzleHttp\Promise\rejection_for($reason);
70
                    }
71
                );
72
            };
73
        };
74
    }
75
}
76