LogMessage::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Facade\Ignition\LogRecorder;
4
5
use Illuminate\Log\Events\MessageLogged;
6
7
class LogMessage
8
{
9
    /** @var string */
10
    protected $message;
11
12
    /** @var array */
13
    protected $context;
14
15
    /** @var string */
16
    protected $level;
17
18
    /** @var float */
19
    protected $microtime;
20
21
    public function __construct(?string $message, string $level, array $context = [], ?float $microtime = null)
22
    {
23
        $this->message = $message;
24
        $this->level = $level;
25
        $this->context = $context;
26
        $this->microtime = $microtime ?? microtime(true);
27
    }
28
29
    public static function fromMessageLoggedEvent(MessageLogged $event): self
30
    {
31
        return new self(
32
            $event->message,
33
            $event->level,
34
            $event->context
35
        );
36
    }
37
38
    public function toArray()
39
    {
40
        return [
41
            'message' => $this->message,
42
            'level' => $this->level,
43
            'context' => $this->context,
44
            'microtime' => $this->microtime,
45
        ];
46
    }
47
}
48