Completed
Pull Request — master (#5)
by Timothée
03:28
created

ClassNameFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
c 4
b 0
f 0
lcom 0
cbo 0
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A commandReceived() 0 4 1
A commandHandled() 0 4 1
A propertiesUsed() 0 4 1
A commandFailed() 0 8 1
1
<?php
2
namespace League\Tactician\Logger\Formatter;
3
4
use Exception;
5
6
/**
7
 * Returns log messages only dump the Command & Exception's class names.
8
 */
9
class ClassNameFormatter implements Formatter
10
{
11
    /**
12
     * @param object $command
13
     * @return string|null
14
     */
15
    public function commandReceived($command)
16
    {
17
        return 'Command received: ' . get_class($command);
18
    }
19
20
    /**
21
     * @param object $command
22
     * @return string|null
23
     */
24
    public function commandHandled($command)
25
    {
26
        return 'Command succeeded: ' . get_class($command);
27
    }
28
29
    public function propertiesUsed($command)
30
    {
31
        return [];
32
    }
33
34
    /**
35
     * @param object $command
36
     * @param Exception $e
37
     * @return string|null
38
     */
39
    public function commandFailed($command, Exception $e)
40
    {
41
        $commandClass = get_class($command);
42
        $exceptionClass = get_class($e);
43
        $exceptionMessage = $e->getMessage();
44
45
        return "Command failed: {$commandClass} threw the exception {$exceptionClass} ({$exceptionMessage})";
46
    }
47
}
48