Passed
Pull Request — master (#4)
by Jan-Marten
12:17
created

LogOperationVisitor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 4 1
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
14
class LogOperationVisitor implements OperationVisitorInterface
15
{
16
    /** @var LoggerInterface */
17
    private $logger;
18
19
    /** @var OperationFormatterInterface */
20
    private $formatter;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param LoggerInterface             $logger
26
     * @param OperationFormatterInterface $formatter
27
     */
28 1
    public function __construct(
29
        LoggerInterface $logger,
30
        OperationFormatterInterface $formatter = null
31
    ) {
32 1
        $this->logger    = $logger;
33 1
        $this->formatter = $formatter ?? new OperationFormatter();
34 1
    }
35
36
    /**
37
     * Visit the given operation.
38
     *
39
     * @param OperationInterface $operation
40
     *
41
     * @return void
42
     */
43 1
    public function __invoke(OperationInterface $operation): void
44
    {
45 1
        $this->logger->info(
46 1
            $this->formatter->format($operation)
47
        );
48 1
    }
49
}
50