Total Complexity | 8 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class AlertBox |
||
6 | { |
||
7 | /** |
||
8 | * @param array $message array of messages, last item in array should be alert class |
||
9 | * @return bool|string |
||
10 | */ |
||
11 | public function alertBox(array $message) |
||
12 | { |
||
13 | $class = $this->getClass($message); |
||
14 | |||
15 | $alert = '<div class="alert '.$class.'"><button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
||
16 | <span aria-hidden="true">×</span> |
||
17 | </button>'.$this->renderMessage($message).'</div>'; |
||
18 | return $alert; |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @param array $message |
||
23 | * @return string |
||
24 | */ |
||
25 | private function getClass(array $message) |
||
26 | { |
||
27 | if(count($message) < 2) { |
||
28 | return 'alert-info'; |
||
29 | } |
||
30 | $class = array_pop($message); |
||
31 | $class = (!strstr($class, 'alert-')) ? 'alert-'.$class : ''; |
||
32 | return $class; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param array $message |
||
37 | * @return string |
||
38 | */ |
||
39 | private function renderMessage(array $message) |
||
54 | } |
||
55 | } |