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.
Test Setup Failed
Push — master ( 7189fb...894091 )
by Carsten
13:12 queued 11s
created

LogExceptionMiddleware::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 22
loc 22
ccs 6
cts 6
cp 1
rs 9.568
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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 5
     */
21
    public $log;
22 5
23 5
24
    /**
25
     * @param LoggerInterface $log
26
     */
27
    public function __construct(LoggerInterface $log)
28
    {
29
        $this->log = $log;
30
    }
31
32
    
33 5
    /**
34
     * PSR-15 Single Pass
35
     * 
36
     * @param  ServerRequestInterface  $request Server reuest instance
37
     * @param  RequestHandlerInterface $handler Request handler
38 5
     * @return ResponseInterface
39
     */
40 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 5
        try {
43
            $response = $handler->handle($request);            
44 4
            return $response;
45 4
        }
46
        // Executed only in PHP 7, will not match in PHP 5.x
47
        catch (\Throwable $e)
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
48
        {
49 1
            $this->handleThrowable( $e );
50
            throw $e;
51 1
        }
52 1
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 5
63
64
65 5
    /**
66 5
     * PSR-7 Double Pass
67 5
     * 
68 5
     * @param RequestInterface   $request   Request instance
69 1
     * @param ResponseInterface  $response  Response instance
70
     * @param callable           $next      Middelware callable
71 5
     *
72 5
     * @return ResponseInterface
73 5
     */
74 5 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 5
    {
76 5
        try
77 5
        {
78 1
            // Try to do business as usual...
79 1
            return $next($request, $response);
80
        }
81 5
82 5
        // Executed only in PHP 7, will not match in PHP 5.x
83
        catch (\Throwable $e)
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
84
        {
85
            $this->handleThrowable( $e );
86
            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
    public function handleThrowable( $e )
102
    {
103
        $context = [
104
            'class'   => get_class($e),
105
            'code'    => $e->getCode(),
106
            'file'    => $e->getFile(),
107
            'line'    => $e->getLine(),
108
        ];
109
110
        if ($f = $e->getPrevious()) {
111
            $context['previous'] = implode(' / ', [
112
                $f->getMessage(),
113
                'class: ' . get_class($f),
114
                'code: ' . $f->getCode(),
115
                'file: ' . $f->getFile(),
116
                'line: ' . $f->getLine(),
117
            ]);
118
        }
119
120
        $this->log->warning($e->getMessage(), $context);
121
    }
122
123
}
124