Passed
Push — develop ( 5fc28f...93d639 )
by Michał
16:38
created

DefaultJsonMessage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 48
rs 10
ccs 12
cts 14
cp 0.8571
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createMessage() 0 16 2
A getMessage() 0 6 1
1
<?php
2
3
namespace SimpleLog\Message;
4
5
class DefaultJsonMessage extends DefaultMessage
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $message = [
11
        'date' => '',
12
        'time' => '',
13
        'data' => '',
14
    ];
15
16
    /**
17
     * @var array
18
     */
19
    protected $context = [];
20
21
    /**
22
     * @param string|array|object $message
23
     * @param array $context
24
     * @return $this
25
     */
26 4
    public function createMessage($message, array $context)
27
    {
28 4
        $this->context = $context;
29
30 4
        list($date, $time) = explode(';', strftime('%d-%m-%Y;%H:%M:%S', time()));
31
32 4
        $this->message['date'] = $date;
33 4
        $this->message['time'] = $time;
34
35 4
        if (method_exists($message, '__toString')) {
36
            $message = (string)$message;
37
        }
38
39 4
        $this->message['data'] = $message;
40
41 4
        return $this;
42
    }
43
44
    /**
45
     * @return string
46
     */
47 4
    public function getMessage()
48
    {
49 4
        $this->message = json_encode($this->message);
0 ignored issues
show
Documentation Bug introduced by
It seems like json_encode($this->message) of type string is incompatible with the declared type array of property $message.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50 4
        $this->buildContext($this->context);
51
52 4
        return $this->message;
53
    }
54
}
55