Completed
Push — master ( 3c1969...5b5792 )
by Schlaefer
03:16 queued 10s
created

CakeLogEntry::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Admin\Lib;
14
15
/**
16
 * @bogus the ability to see logs isn't in Saito 5 anymore; see also AdminHelper::formatCakeLog
17
 */
18
class CakeLogEntry
19
{
20
    /**
21
     * Time
22
     *
23
     * @var string
24
     */
25
    protected $_time;
26
27
    /**
28
     * Time
29
     *
30
     * @var string
31
     */
32
    protected $_type;
33
34
    /**
35
     * Message
36
     *
37
     * @var string
38
     */
39
    protected $_message;
40
41
    /**
42
     * Detail
43
     *
44
     * @var string
45
     */
46
    protected $_detail;
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $text log entry text
52
     */
53
    public function __construct($text)
54
    {
55
        $lines = explode("\n", trim($text));
56
        $_firstLine = array_shift($lines);
57
        preg_match(
58
            '/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (.*?): (.*)/',
59
            $_firstLine,
60
            $matches
61
        );
62
        $this->_time = $matches[1];
63
        $this->_type = $matches[2];
64
        $this->_message = trim($matches[3]);
65
        if (empty($this->_message)) {
66
            $this->_message = array_shift($lines);
67
        }
68
        $this->_detail = implode($lines, '<br>');
69
    }
70
71
    /**
72
     * Gets log entry time
73
     *
74
     * @return string
75
     */
76
    public function time()
77
    {
78
        return $this->_time;
79
    }
80
81
    /**
82
     * Gets log entry type
83
     *
84
     * @return string
85
     */
86
    public function type()
87
    {
88
        return $this->_type;
89
    }
90
91
    /**
92
     * Gets log entry message
93
     *
94
     * @return string
95
     */
96
    public function message()
97
    {
98
        return $this->_message;
99
    }
100
101
    /**
102
     * Gets log entry details
103
     *
104
     * @return string
105
     */
106
    public function details()
107
    {
108
        return $this->_detail;
109
    }
110
}
111