LoggerMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 14
c 1
b 0
f 1
dl 0
loc 26
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\SharedKernel\Infrastructure\HttpClient\Middleware;
6
7
use Psr\Http\Message\RequestInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\RequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Psr\Http\Message\ResponseInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
final class LoggerMiddleware
12
{
13
    private LoggerInterface $logger;
14
15
    public function __construct(LoggerInterface $logger)
16
    {
17
        $this->logger = $logger;
18
    }
19
20
    public function __invoke(callable $handler): callable
21
    {
22
        $logger = $this->logger;
23
24
        return static function (callable $handler) use ($logger) {
25
            return static function (RequestInterface $request, array $options) use ($handler, $logger) {
26
                $promise = $handler($request, $options);
27
28
                return $promise->then(
29
                    function (ResponseInterface $response) use ($request, $logger) {
30
                        $requestBody = $request->getBody();
31
                        $logger->info($requestBody->getContents());
32
33
                        $responseBody = $response->getBody();
34
                        $logger->info($responseBody->getContents());
35
36
                        return $response;
37
                    }
38
                );
39
            };
40
        };
41
    }
42
}
43