Message   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 32
c 2
b 1
f 0
dl 0
loc 79
ccs 27
cts 27
cp 1
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getTypeUnicodeSymbol() 0 23 6
A __construct() 0 10 2
1
<?php
2
/**
3
 * Message Classs
4
 * 
5
 * @category Logging
6
 * 
7
 * @author    Vitex <[email protected]>
8
 * @copyright 2019 [email protected] (G)
9
 * @license   https://opensource.org/licenses/MIT MIT
10
 * 
11
 * PHP 7
12
 */
13
14
namespace Ease\Logger;
15
16
/**
17
 * Description of Message
18
 *
19
 * @author vitex
20
 */
21
class Message
22
{
23
    /**
24
     * Message body
25
     *
26
     * @var string
27
     */
28
    public $body;
29
30
    /**
31
     * Message type
32
     *
33
     * @var string info|succes|warning|danger|mail
34
     */
35
    public $type;
36
37
    /**
38
     * 
39
     * @var \Ease\Atom
40
     */
41
    public $caller;
42
43
    /**
44
     * Message Timestamp
45
     *
46
     * @var int
47
     */
48
    public $when;
49
50
    /**
51
     * Basic Message class
52
     * 
53
     * @param string     $message text
54
     * @param string     $type    One of info|notice|debug|error
55 2
     * @param \Ease\Atom $caller  Origin of message
56
     * @param int        $when    Timestamp
57
     */
58 2
    public function __construct($message, $type = 'info', $caller = null,
59 2
        $when = null
60 2
    ) {
61 2
        $this->body   = $message;
62 2
        $this->type   = $type;
63
        $this->caller = $caller;
64 1
        if (is_null($when)) {
65
            $this->when = time();
66 2
        } else {
67
            $this->when = $when;
68
        }
69
    }
70
71
    /**
72
     * Unicode Symbol for given message type
73
     *
74 1
     * @param  string $type
75
     * @return string
76
     */
77 1
    public static function getTypeUnicodeSymbol($type)
78 1
    {
79 1
        switch ($type) {
80 1
        case 'mail':                       // Envelope
81 1
            $symbol = '✉';
82 1
            break;
83 1
        case 'warning':                    // Vykřičník v trojůhelníku
84 1
            $symbol = '⚠';
85 1
            break;
86 1
        case 'error':                      // Lebka
87 1
            $symbol = '☠';
88 1
            break;
89 1
        case 'success':                    // Kytička
90 1
            $symbol = '❁';
91 1
            break;
92
        case 'debug':                      // Gear
93 1
            $symbol = '⚙';
94 1
            break;
95
        default:                           // i v kroužku
96 1
            $symbol = 'ⓘ';
97
            break;
98
        }
99
        return $symbol;
100
    }
101
}
102