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 (#156)
by
unknown
01:44
created

RequestTimeMiddleware::__invoke()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace EightPoints\Bundle\GuzzleBundle\Middleware;
4
5
use EightPoints\Bundle\GuzzleBundle\DataCollector\HttpDataCollector;
6
use Psr\Http\Message\RequestInterface;
7
use GuzzleHttp\TransferStats;
8
9
class RequestTimeMiddleware
10
{
11
    /** @var \EightPoints\Bundle\GuzzleBundle\DataCollector\HttpDataCollector */
12
    private $dataCollector;
13
14
    /**
15
     * @param \EightPoints\Bundle\GuzzleBundle\DataCollector\HttpDataCollector $dataCollector
16
     */
17
    public function __construct(HttpDataCollector $dataCollector)
18
    {
19
        $this->dataCollector = $dataCollector;
20
    }
21
22
    /**
23
     * @param callable $handler
24
     *
25
     * @return \Closure
26
     */
27
    public function __invoke(callable $handler) : \Closure
28
    {
29
        return function (
30
            RequestInterface $request,
31
            array $options
32
        ) use ($handler) {
33
            $options['on_stats'] = $this->getOnStatsCallback(isset($options['on_stats']) ? $options['on_stats'] : null);
34
35
            // Continue the handler chain.
36
            return $handler($request, $options);
37
        };
38
    }
39
40
    /**
41
     * Create callback for on_stats options.
42
     * If request has on_stats option, it will be called inside of this callback.
43
     *
44
     * @param null|\Closure $initialOnStats
45
     *
46
     * @return \Closure
47
     */
48
    protected function getOnStatsCallback(\Closure $initialOnStats = null) : \Closure
49
    {
50
        return function (TransferStats $stats) use ($initialOnStats) {
51
            if (is_callable($initialOnStats)) {
52
                call_user_func($initialOnStats, $stats);
53
            }
54
55
            $this->dataCollector->addTotalTime((float)$stats->getTransferTime());
56
        };
57
    }
58
}
59