CommandLogger   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\PHPCommandBus\Middleware;
6
7
use Psr\Log;
8
use RemotelyLiving\PHPCommandBus\Enums;
9
use RemotelyLiving\PHPCommandBus\Interfaces;
10
use RemotelyLiving\PHPCommandBus\Traits;
11
12
final class CommandLogger implements Log\LoggerAwareInterface
13
{
14
    use Traits\Logger;
15
16
    public function __invoke(object $command, callable $next): void
17
    {
18
        if ($command instanceof Interfaces\LoggableCommand) {
19
            $this->getLogger()->log(
20
                (string) ($command->getLogLevel() ?? Enums\LogLevel::INFO()),
21
                $command->getLogMessage(),
22
                $command->getLogContext()
23
            );
24
        }
25
26
        $next($command);
27
    }
28
}
29