Completed
Push — master ( 1d94aa...24ca76 )
by Roj
02:51
created

BootstrapThreePresenter::getClassNameSuffix()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace Rojtjo\Notifier\Presenters;
4
5
use Rojtjo\Notifier\Notification;
6
use Rojtjo\Notifier\Notifications;
7
use Rojtjo\Notifier\Presenter;
8
9
class BootstrapThreePresenter implements Presenter
10
{
11
    /**
12
     * @var array
13
     */
14
    private $classNameSuffixMap = [
15
        'success' => 'success',
16
        'error' => 'danger',
17
        'warning' => 'warning',
18
        'info' => 'info',
19
    ];
20
21
    /**
22
     * @param Notifications $notifications
23
     * @return string
24
     */
25 3
    public function render(Notifications $notifications)
26
    {
27 3
        $output = '';
28 3
        foreach($notifications as $notification) {
29 3
            $output .= $this->renderNotification($notification);
30 3
        }
31
32 3
        return $output;
33
    }
34
35
    /**
36
     * @param Notification $notification
37
     * @return string
38
     */
39 3
    private function renderNotification(Notification $notification)
40
    {
41 3
        $classNameSuffix = $this->getClassNameSuffix($notification->getType());
42
        return <<<HTML
43 3
<div class="alert alert-{$classNameSuffix}" role="alert">
44 3
    {$notification->getMessage()}
45
</div>
46
47 3
HTML;
48
    }
49
50
    /**
51
     * @param string $type
52
     * @return string
53
     */
54 3
    private function getClassNameSuffix($type)
55
    {
56 3
        if(!isset($this->classNameSuffixMap[$type])) {
57
            return 'default';
58
        }
59
60 3
        return $this->classNameSuffixMap[$type];
61
    }
62
}
63