Message   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 81
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 12
lcom 2
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setMessage() 0 5 1
A setType() 0 5 1
A getMessage() 0 4 1
A getType() 0 4 1
B checkType() 0 13 7
1
<?php
2
namespace FMUP\FlashMessenger;
3
4
/**
5
 * Description of Flash
6
 *
7
 * @author sweffling
8
 */
9
class Message
10
{
11
12
    private $message;
13
    private $type = self::TYPE_DEFAULT;
14
15
    const TYPE_DEFAULT = 'default';
16
    const TYPE_SUCCESS = 'success';
17
    const TYPE_INFO = 'info';
18
    const TYPE_WARNING = 'warning';
19
    const TYPE_DANGER = 'danger';
20
21
    /**
22
     * Construct a new flash message
23
     * @param string $message
24
     * @param string $type
25
     */
26 3
    public function __construct($message, $type = self::TYPE_DEFAULT)
27
    {
28 3
        $this->setType($type)->setMessage($message);
29 3
    }
30
31
    /**
32
     * Set message property
33
     * @param string $message
34
     * @return $this
35
     */
36 3
    public function setMessage($message)
37
    {
38 3
        $this->message = (string)$message;
39 3
        return $this;
40
    }
41
42
    /**
43
     * Set type property
44
     * @param string $type
45
     * @return $this
46
     */
47 3
    public function setType($type)
48
    {
49 3
        $this->type = $this->checkType($type);
50 3
        return $this;
51
    }
52
53
    /**
54
     * Get message property
55
     * @return string $message
56
     */
57 1
    public function getMessage()
58
    {
59 1
        return (string)$this->message;
60
    }
61
62
    /**
63
     * Get message property
64
     * @return string|null $type
65
     */
66 1
    public function getType()
67
    {
68 1
        return $this->type;
69
    }
70
71
    /**
72
     * Checks if the type given is valid
73
     * @param string $type
74
     * @return string
75
     */
76 3
    private function checkType($type)
77
    {
78 3
        if ($type !== self::TYPE_DANGER &&
79 3
            $type !== self::TYPE_DEFAULT &&
80 3
            $type !== self::TYPE_INFO &&
81 3
            $type !== self::TYPE_SUCCESS &&
82 3
            $type !== self::TYPE_WARNING
83
        ) {
84 1
            return ($this->getType() !== null) ? $this->getType() : self::TYPE_DEFAULT;
85
        } else {
86 3
            return $type;
87
        }
88
    }
89
}
90