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.
Completed
Push — master ( 19a8d1...db5248 )
by Eric
68:12 queued 65:17
created

ErrorPlugin::handleRequest()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 1
nop 3
crap 4
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Service\Plugin;
13
14
use Http\Client\Common\Exception\ClientErrorException;
15
use Http\Client\Common\Exception\ServerErrorException;
16
use Http\Client\Common\Plugin;
17
use Psr\Http\Message\RequestInterface;
18
use Psr\Http\Message\ResponseInterface;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class ErrorPlugin implements Plugin
24
{
25
    /**
26
     * @var string[]
27
     */
28
    private static $errors = [
29
        'ERROR'                   => ServerErrorException::class,
30
        'INVALID_REQUEST'         => ClientErrorException::class,
31
        'MAX_DIMENSIONS_EXCEEDED' => ClientErrorException::class,
32
        'MAX_ELEMENTS_EXCEEDED'   => ClientErrorException::class,
33
        'MAX_WAYPOINTS_EXCEEDED'  => ClientErrorException::class,
34
        'NOT_FOUND'               => ClientErrorException::class,
35
        'OVER_QUERY_LIMIT'        => ServerErrorException::class,
36
        'REQUEST_DENIED'          => ClientErrorException::class,
37
        'UNKNOWN_ERROR'           => ServerErrorException::class,
38
    ];
39
40
    /**
41
     * @var string[]
42
     */
43
    private static $placeholders = [
44
        '"status" : "%s"',
45
        '<status>%s</status>',
46
    ];
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
52
    {
53 1028
        return $next($request)->then(function (ResponseInterface $response) use ($request) {
54 1028
            $body = (string) $response->getBody();
55
56 1028
            foreach (self::$errors as $error => $exception) {
57 1028
                foreach (self::$placeholders as $placeholder) {
58 1028
                    if (strpos($body, sprintf($placeholder, $error)) !== false) {
59 566
                        throw new $exception($error, $request, $response);
60
                    }
61 514
                }
62 514
            }
63
64 924
            return $response;
65 1028
        });
66
    }
67
}
68