Notification::fromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Rojtjo\Notifier;
4
5
class Notification
6
{
7
    /**
8
     * @var string
9
     */
10
    private $type;
11
12
    /**
13
     * @var string
14
     */
15
    private $message;
16
17
    /**
18
     * @param string $type
19
     * @param string $message
20
     */
21 54
    public function __construct($type, $message)
22
    {
23 54
        $this->type = $type;
24 54
        $this->message = $message;
25 54
    }
26
27
    /**
28
     * @param array $data
29
     * @return Notification
30
     */
31 9
    public static function fromArray(array $data)
32
    {
33 9
        return new Notification(
34 9
            $data['type'],
35 9
            $data['message']
36 9
        );
37
    }
38
39
    /**
40
     * @param string $message
41
     * @return Notification
42
     */
43 30
    public static function success($message)
44
    {
45 30
        return new Notification('success', $message);
46
    }
47
48
    /**
49
     * @param string $message
50
     * @return Notification
51
     */
52 18
    public static function error($message)
53
    {
54 18
        return new Notification('error', $message);
55
    }
56
57
    /**
58
     * @param string $message
59
     * @return Notification
60
     */
61 9
    public static function warning($message)
62
    {
63 9
        return new Notification('warning', $message);
64
    }
65
66
    /**
67
     * @param string $message
68
     * @return Notification
69
     */
70 9
    public static function info($message)
71
    {
72 9
        return new Notification('info', $message);
73
    }
74
75
    /**
76
     * @return string
77
     */
78 30
    public function getType()
79
    {
80 30
        return $this->type;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 30
    public function getMessage()
87
    {
88 30
        return $this->message;
89
    }
90
}
91