AuditMiddleware::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 9
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\SharedKernel\Infrastructure\Messenger\Middleware;
6
7
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...
8
use Symfony\Component\Messenger\Envelope;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Messenger\Envelope 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 Symfony\Component\Messenger\Middleware\MiddlewareInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Messen...are\MiddlewareInterface 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
use Symfony\Component\Messenger\Middleware\StackInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Messen...ddleware\StackInterface 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...
11
12
final class AuditMiddleware implements MiddlewareInterface
13
{
14
    private LoggerInterface $logger;
15
16
    public function __construct(LoggerInterface $logger)
17
    {
18
        $this->logger = $logger;
19
    }
20
21
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
22
    {
23
        $message = $envelope->getMessage();
24
        $className = get_class($message);
25
26
        $body = [];
27
        foreach ((array) $message as $key => $value) {
28
            $body[$this->receivedVariableName($key, $className)] = $value;
29
        }
30
31
        $this->logger->info(sprintf('Received & handling %s', $className), $body);
32
33
        $next = $stack->next();
34
35
        return $next->handle($envelope, $stack);
36
    }
37
38
    private function receivedVariableName(string $name, string $class): string
39
    {
40
        return (string) preg_replace('/[\x00-\x1F\x7F]/', '', str_replace($class, '', $name));
41
    }
42
}
43