Completed
Push — master ( fa732c...3d1320 )
by Ross
9s
created

ClassNameFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 4
c 7
b 1
f 0
lcom 3
cbo 1
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A logCommandReceived() 0 4 1
A logCommandSucceeded() 0 4 1
A logCommandFailed() 0 8 1
1
<?php
2
namespace League\Tactician\Logger\Formatter;
3
4
use Exception;
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\LogLevel;
7
8
/**
9
 * Returns log messages only dump the Command & Exception's class names.
10
 */
11
class ClassNameFormatter implements Formatter
12
{
13
    /**
14
     * @var string
15
     */
16
    private $commandReceivedLevel;
17
18
    /**
19
     * @var string
20
     */
21
    private $commandSucceededLevel;
22
23
    /**
24
     * @var string
25
     */
26
    private $commandFailedLevel;
27
28
    /**
29
     * @param string $commandReceivedLevel
30
     * @param string $commandSucceededLevel
31
     * @param string $commandFailedLevel
32
     */
33
    public function __construct(
34
        $commandReceivedLevel = LogLevel::DEBUG,
35
        $commandSucceededLevel = LogLevel::DEBUG,
36
        $commandFailedLevel = LogLevel::ERROR
37
    ) {
38
        $this->commandReceivedLevel = $commandReceivedLevel;
39
        $this->commandSucceededLevel = $commandSucceededLevel;
40
        $this->commandFailedLevel = $commandFailedLevel;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function logCommandReceived(LoggerInterface $logger, $command)
47
    {
48
        $logger->log($this->commandReceivedLevel, 'Command received: ' . get_class($command), []);
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function logCommandSucceeded(LoggerInterface $logger, $command, $returnValue)
55
    {
56
        $logger->log($this->commandSucceededLevel, 'Command succeeded: ' . get_class($command), []);
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function logCommandFailed(LoggerInterface $logger, $command, Exception $e)
63
    {
64
        $logger->log(
65
            $this->commandFailedLevel,
66
            'Command failed: ' . get_class($command),
67
            ['exception' => $e]
68
        );
69
    }
70
}
71