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 ( 894091...53b59c )
by Carsten
08:57 queued 05:38
created

LogExceptionMiddleware::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 5.667

Importance

Changes 0
Metric Value
dl 22
loc 22
ccs 3
cts 9
cp 0.3333
rs 9.568
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 5.667
1
<?php
2
3
namespace Germania\Middleware;
4
5
use Psr\Log\LoggerInterface;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
12
13
14
15
16
class LogExceptionMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @var LoggerInterface
20
     */
21
    public $log;
22
23
24
    /**
25
     * @param LoggerInterface $log
26
     */
27 12
    public function __construct(LoggerInterface $log)
28
    {
29 12
        $this->log = $log;
30 12
    }
31
32
    
33
    /**
34
     * PSR-15 Single Pass
35
     * 
36
     * @param  ServerRequestInterface  $request Server reuest instance
37
     * @param  RequestHandlerInterface $handler Request handler
38
     * @return ResponseInterface
39
     */
40 4 View Code Duplication
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        try {
43 4
            $response = $handler->handle($request);            
44 4
            return $response;
45
        }
46
        // Executed only in PHP 7, will not match in PHP 5.x
47
        catch (\Throwable $e)
48
        {
49
            $this->handleThrowable( $e );
50
            throw $e;
51
        }
52
53
        // Executed only in PHP 5.x, will not be reached in PHP 7
54
        catch (\Exception $e)
55
        {
56
            $this->handleThrowable( $e );
57
            throw $e;
58
        }        
59
60
        
61
    }     
62
63
64
65
    /**
66
     * PSR-7 Double Pass
67
     * 
68
     * @param RequestInterface   $request   Request instance
69
     * @param ResponseInterface  $response  Response instance
70
     * @param callable           $next      Middelware callable
71
     *
72
     * @return ResponseInterface
73
     */
74 4 View Code Duplication
    public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        try
77
        {
78
            // Try to do business as usual...
79 4
            return $next($request, $response);
80
        }
81
82
        // Executed only in PHP 7, will not match in PHP 5.x
83 4
        catch (\Throwable $e)
84
        {
85 4
            $this->handleThrowable( $e );
86 4
            throw $e;
87
        }
88
89
        // Executed only in PHP 5.x, will not be reached in PHP 7
90
        catch (\Exception $e)
91
        {
92
            $this->handleThrowable( $e );
93
            throw $e;
94
        }
95
    }
96
97
98
    /**
99
     * @param  \Exception|\Throwable $e
100
     */
101 4
    public function handleThrowable( $e )
102
    {
103
        $context = [
104 4
            'class'   => get_class($e),
105 4
            'code'    => $e->getCode(),
106 4
            'file'    => $e->getFile(),
107 4
            'line'    => $e->getLine(),
108
        ];
109
110 4
        if ($f = $e->getPrevious()) {
111 4
            $context['previous'] = implode(' / ', [
112 4
                $f->getMessage(),
113 4
                'class: ' . get_class($f),
114 4
                'code: ' . $f->getCode(),
115 4
                'file: ' . $f->getFile(),
116 4
                'line: ' . $f->getLine(),
117
            ]);
118
        }
119
120 4
        $this->log->warning($e->getMessage(), $context);
121 4
    }
122
123
}
124