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

LogHttpStatusMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 50.67 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 38
loc 75
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 18 18 1
A __invoke() 20 20 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Germania\Middleware;
3
4
use Psr\Log\LoggerInterface;
5
use Psr\Log\LoggerAwareTrait;
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
17
/**
18
 * Writes the HTTP Response's status code and reason to a PSR-3 Logger.
19
 */
20
class LogHttpStatusMiddleware implements MiddlewareInterface
21
{
22
    use LoggerAwareTrait;
23
24
25
    /**
26 10
     * @param LoggerInterface $logger    PSR-3 Logger instance
27
     */
28 10
    public function __construct( LoggerInterface $logger )
29 10
    {
30
        $this->logger = $logger;
31
    }
32
33
34
35
    
36
    /**
37
     * PSR-15 Single Pass
38
     * 
39
     * @param  ServerRequestInterface  $request Server reuest instance
40 10
     * @param  RequestHandlerInterface $handler Request handler
41
     * @return ResponseInterface
42
     */
43 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...
44 10
    {
45
46
        $response = $handler->handle($request);            
47
48
        // Now that all is done,
49 10
        // concat to a string and send it to the PSR-3 Logger.
50 10
        $status = $response->getStatusCode();
51
        $reason = $response->getReasonPhrase();
52 10
53
        $msg = sprintf("%s %s", $status, $reason);
54 10
55 8
        $this->logger->info("Response", [
56 2
            'status' => $msg
57
        ]);
58 10
59
        return $response;
60
    }     
61
62
63
64
    /**
65
     * PSR-7 Double Pass
66
     * 
67
     * @param RequestInterface   $request   Request instance
68
     * @param ResponseInterface  $response  Response instance
69
     * @param callable           $next      Middelware callable
70
     *
71
     * @return ResponseInterface
72
     */
73 View Code Duplication
    public function __invoke( ServerRequestInterface $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...
74
    {
75
        // Do nothing before $next,
76
        // instead call $next first.
77
        $response = $next($request, $response);
78
79
80
        // Now that all is done,
81
        // concat to a string and send it to the PSR-3 Logger.
82
        $status = $response->getStatusCode();
83
        $reason = $response->getReasonPhrase();
84
85
        $msg = sprintf("%s %s", $status, $reason);
86
87
        $this->logger->info("Response", [
88
            'status' => $msg
89
        ]);
90
91
        return $response;
92
    }
93
94
}
95