Passed
Push — master ( 2b46a2...d3fa0b )
by
unknown
01:36 queued 11s
created

LogOperationVisitor::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Johmanx10\Transaction\Visitor;
8
9
use Johmanx10\Transaction\Formatter\OperationFormatter;
10
use Johmanx10\Transaction\Formatter\OperationFormatterInterface;
11
use Johmanx10\Transaction\OperationInterface;
12
use Psr\Log\LoggerInterface;
13
use Psr\Log\LogLevel;
14
15
class LogOperationVisitor implements OperationVisitorInterface
16
{
17
    /** @var LoggerInterface */
18
    private $logger;
19
20
    /** @var OperationFormatterInterface */
21
    private $formatter;
22
23
    /** @var string */
24
    private $logLevel;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param LoggerInterface             $logger
30
     * @param OperationFormatterInterface $formatter
31
     * @param string                      $logLevel
32
     */
33 1
    public function __construct(
34
        LoggerInterface $logger,
35
        OperationFormatterInterface $formatter = null,
36
        string $logLevel = LogLevel::INFO
37
    ) {
38 1
        $this->logger    = $logger;
39 1
        $this->formatter = $formatter ?? new OperationFormatter();
40 1
        $this->logLevel  = $logLevel;
41 1
    }
42
43
    /**
44
     * Visit the given operation.
45
     *
46
     * @param OperationInterface $operation
47
     *
48
     * @return void
49
     */
50 1
    public function __invoke(OperationInterface $operation): void
51
    {
52 1
        $this->logger->log(
53 1
            $this->logLevel,
54 1
            $this->formatter->format($operation)
55
        );
56 1
    }
57
}
58