LogEntry   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 114
rs 10
wmc 15

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getOwner() 0 3 1
A setUpdatedAt() 0 3 1
A setCreatedAt() 0 3 1
A getContext() 0 3 1
A getCreatedAt() 0 3 1
A getMessage() 0 3 1
A getLevels() 0 11 1
A setContext() 0 3 1
A setLevel() 0 9 1
A getId() 0 3 1
A getUpdatedAt() 0 3 1
A setOwner() 0 3 1
A getLevel() 0 3 1
A setMessage() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLogEntryPlugin\Model;
6
7
use DateTimeInterface;
8
use Psr\Log\LogLevel;
9
use Webmozart\Assert\Assert;
10
11
abstract class LogEntry implements LogEntryInterface
12
{
13
    /** @var mixed */
14
    protected $id;
15
16
    /** @var LogEntriesAwareInterface|null */
17
    protected $owner;
18
19
    /** @var string */
20
    protected $level;
21
22
    /** @var string */
23
    protected $message;
24
25
    /** @var array|null */
26
    protected $context;
27
28
    /** @var DateTimeInterface */
29
    protected $createdAt;
30
31
    /** @var DateTimeInterface|null */
32
    protected $updatedAt;
33
34
    public function __construct()
35
    {
36
        $this->setLevel(LogLevel::INFO);
37
    }
38
39
    public function getOwner(): ?LogEntriesAwareInterface
40
    {
41
        return $this->owner;
42
    }
43
44
    public function setOwner(?LogEntriesAwareInterface $owner): void
45
    {
46
        $this->owner = $owner;
47
    }
48
49
    public static function getLevels(): array
50
    {
51
        return [
52
            LogLevel::EMERGENCY => LogLevel::EMERGENCY,
53
            LogLevel::ALERT => LogLevel::ALERT,
54
            LogLevel::CRITICAL => LogLevel::CRITICAL,
55
            LogLevel::ERROR => LogLevel::ERROR,
56
            LogLevel::WARNING => LogLevel::WARNING,
57
            LogLevel::NOTICE => LogLevel::NOTICE,
58
            LogLevel::INFO => LogLevel::INFO,
59
            LogLevel::DEBUG => LogLevel::DEBUG,
60
        ];
61
    }
62
63
    /**
64
     * @return mixed
65
     */
66
    public function getId()
67
    {
68
        return $this->id;
69
    }
70
71
    public function getLevel(): string
72
    {
73
        return $this->level;
74
    }
75
76
    public function setLevel(string $level): void
77
    {
78
        Assert::oneOf(
79
            $level,
80
            self::getLevels(),
81
            'Wrong log entry level. Expected one of: %2$s. Got: %s'
82
        );
83
84
        $this->level = $level;
85
    }
86
87
    public function getMessage(): ?string
88
    {
89
        return $this->message;
90
    }
91
92
    public function setMessage(string $message): void
93
    {
94
        $this->message = $message;
95
    }
96
97
    public function getContext(): ?array
98
    {
99
        return $this->context;
100
    }
101
102
    public function setContext(array $context): void
103
    {
104
        $this->context = $context;
105
    }
106
107
    public function getCreatedAt(): ?DateTimeInterface
108
    {
109
        return $this->createdAt;
110
    }
111
112
    public function setCreatedAt(DateTimeInterface $createdAt): void
113
    {
114
        $this->createdAt = $createdAt;
115
    }
116
117
    public function getUpdatedAt(): ?DateTimeInterface
118
    {
119
        return $this->updatedAt;
120
    }
121
122
    public function setUpdatedAt(DateTimeInterface $updatedAt): void
123
    {
124
        $this->updatedAt = $updatedAt;
125
    }
126
}
127