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.

SymfonyLogMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 24
rs 9.8333
1
<?php
2
3
namespace EightPoints\Bundle\GuzzleBundle\Middleware;
4
5
use GuzzleHttp\Exception\RequestException;
6
use GuzzleHttp\MessageFormatter;
7
use Psr\Log\LoggerInterface;
8
9
class SymfonyLogMiddleware
10
{
11
    /** @var \GuzzleHttp\MessageFormatter */
12
    protected $formatter;
13
14
    /** @var \Psr\Log\LoggerInterface */
15
    protected $logger;
16
17
    /**
18
     * @param \Psr\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
     * @param callable $handler
29
     *
30
     * @return \Closure
31
     */
32
    public function __invoke(callable $handler) : \Closure
33
    {
34
        $logger    = $this->logger;
35
        $formatter = $this->formatter;
36
37
        return function ($request, array $options) use ($handler, $logger, $formatter) {
38
39
            return $handler($request, $options)->then(
40
41
                function ($response) use ($logger, $request, $formatter) {
42
                    $message = $formatter->format($request, $response);
43
44
                    $logger->info($message);
45
46
                    return $response;
47
                },
48
49
                function ($reason) use ($logger, $request, $formatter) {
50
                    $response = $reason instanceof RequestException ? $reason->getResponse() : null;
51
                    $message  = $formatter->format($request, $response, $reason);
52
53
                    $logger->notice($message);
54
55
                    return \GuzzleHttp\Promise\rejection_for($reason);
56
                }
57
            );
58
        };
59
    }
60
}
61