BootstrapFormMessage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A BootstrapAlertType() 0 3 1
A getAlertType() 0 12 3
1
<?php
2
3
namespace LeKoala\Admini\Forms;
4
5
trait BootstrapFormMessage
6
{
7
    /**
8
     * @var string[]
9
     */
10
    protected static $bootstrapAlertsMap = [
11
        'success' => 'alert-success',
12
        'good' => 'alert-success',
13
        'error' => 'alert-danger',
14
        'bad' => 'alert-danger',
15
        'required' => 'alert-danger',
16
        'warning' => 'alert-warning',
17
        'info' => 'alert-info',
18
    ];
19
20
    /**
21
     * Maps a SilverStripe message type to a Bootstrap alert type
22
     */
23
    public function getAlertType()
24
    {
25
        $type = $this->owner->getMessageType();
26
        if (!$type) {
27
            $type = 'info';
28
        }
29
        if (isset(self::$bootstrapAlertsMap[$type])) {
30
            return self::$bootstrapAlertsMap[$type];
31
        }
32
33
        // Fallback to original
34
        return $type;
35
    }
36
37
    public function BootstrapAlertType()
38
    {
39
        return $this->getAlertType();
40
    }
41
}
42