AlertBox   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 51
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A alertBox() 0 9 1
A getClass() 0 9 3
A renderMessage() 0 16 4
1
<?php
2
3
namespace Del\Common\View\Helper;
4
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 2
    public function alertBox(array $message)
12
    {
13 2
        $class = $this->getClass($message);
14
15 2
        $alert = '<div class="alert '.$class.'"><button type="button" class="close" data-dismiss="alert" aria-label="Close">
16
                      <span aria-hidden="true">&times;</span>
17 2
                    </button>'.$this->renderMessage($message).'</div>';
18 2
        return $alert;
19
    }
20
21
    /**
22
     * @param array $message
23
     * @return string
24
     */
25 2
    private function getClass(array $message)
26
    {
27 2
        if(count($message) < 2) {
28 1
            return 'alert-info';
29
        }
30 1
        $class = array_pop($message);
31 1
        $class = (!strstr($class, 'alert-')) ? 'alert-'.$class : '';
32 1
        return $class;
33
    }
34
35
    /**
36
     * @param array $message
37
     * @return string
38
     */
39 2
    private function renderMessage(array $message)
40
    {
41 2
        if (isset($message[1])) {
42 1
            unset($message[1]);
43
        }
44 2
        $alert = '';
45 2
        $num = count($message);
46 2
        $x = 1;
47 2
        foreach($message as $msg)
48
        {
49 2
            $alert .= $msg;
50 2
            if($x < $num){$alert .= '<br />';}
51 2
            $x ++;
52
        }
53 2
        return $alert;
54
    }
55
}