CommandLogger::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 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