Completed
Push — master ( 4966ad...2cf3a8 )
by Derek Stephen
02:07
created

AlertBox   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 33
ccs 0
cts 24
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B alertBox() 0 26 6
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
    public function alertBox(array $message)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
12
    {
13
        if(!$message){return false;}
0 ignored issues
show
Bug Best Practice introduced by
The expression $message of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
14
        if(count($message) < 2) {
15
            $class = 'info';
16
        } else {
17
            $class = array_pop($message);
18
        }
19
20
        $alert = '<div class="alert ';
21
        if($class != 'alert'){$alert .= 'alert-'.$class;}
22
        $alert .= '"><button type="button" class="close" data-dismiss="alert" aria-label="Close">
23
                      <span aria-hidden="true">&times;</span>
24
                    </button>';
25
26
        $num = count($message);
27
        $x = 1;
28
        foreach($message as $msg)
29
        {
30
            $alert .= $msg;
31
            if($x < $num){$alert .= '<br />';}
32
            $x ++;
33
        }
34
        $alert .= '</div>';
35
        return $alert;
36
    }
37
}