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 — error-plugin ( 2ba14a...70cc75 )
by Eric
80:00 queued 14:20
created

ErrorPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleRequest() 0 16 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
        return $next($request)->then(function (ResponseInterface $response) use ($request) {
54
            $body = (string) $response->getBody();
55
56
            foreach (self::$errors as $error => $exception) {
57
                foreach (self::$placeholders as $placeholder) {
58
                    if (strpos($body, sprintf($placeholder, $error)) !== false) {
59
                        throw new $exception($error, $request, $response);
60
                    }
61
                }
62
            }
63
64
            return $response;
65
        });
66
    }
67
}
68