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
Push — master ( a859a4...ed53b9 )
by Cees-Jan
01:35
created

WithRandomHeadersMiddleware   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
A __invoke() 0 13 2
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Http\Middleware;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use function React\Promise\resolve;
0 ignored issues
show
Bug introduced by
The type React\Promise\resolve 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...
8
9
final class WithRandomHeadersMiddleware
10
{
11
    private $headers = [];
12
13
    private $minimum = 2;
14
15
    private $maximum = 2;
16
17
    /**
18
     * @param array $headers
19
     */
20 1
    public function __construct(array $headers, int $minimum = 2, int $maximum = 2)
21
    {
22 1
        $this->headers = $headers;
23 1
        $this->minimum = $minimum;
24 1
        $this->maximum = $maximum;
25
26 1
        $headersCount = count($headers);
27 1
        if ($this->minimum > $headersCount) {
28
            $this->minimum = $headersCount;
29
        }
30 1
        if ($this->maximum > $headersCount) {
31
            $this->maximum = $headersCount;
32
        }
33 1
        if ($this->maximum < $this->minimum) {
34
            $this->maximum = $this->minimum;
35
        }
36 1
    }
37
38
    public function __invoke(ServerRequestInterface $request, callable $next)
39
    {
40 1
        return resolve($next($request))->then(function (ResponseInterface $response) {
41 1
            $count = random_int($this->minimum, $this->maximum);
42 1
            $headers = $this->headers;
43 1
            for ($i = 0; $i < $count; $i++) {
44 1
                $randomizer = array_keys($headers);
45 1
                $header = $randomizer[random_int(0, count($headers) - 1)];
46 1
                $response = $response->withHeader($header, $headers[$header]);
47 1
                unset($headers[$header]);
48
            }
49
50 1
            return resolve($response);
51 1
        });
52
    }
53
}
54