BootstrapThreePresenter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 9 2
A renderNotification() 0 10 1
A getClassNameSuffix() 0 8 2
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 array $classNameSuffixMap
23
     */
24 12
    public function __construct(array $classNameSuffixMap = [])
25
    {
26 12
        $this->classNameSuffixMap = array_merge($this->classNameSuffixMap, $classNameSuffixMap);
27 12
    }
28
29
    /**
30
     * @param Notifications $notifications
31
     * @return string
32
     */
33 9
    public function render(Notifications $notifications)
34
    {
35 9
        $output = '';
36 9
        foreach ($notifications as $notification) {
37 9
            $output .= $this->renderNotification($notification);
38 9
        }
39
40 9
        return $output;
41
    }
42
43
    /**
44
     * @param Notification $notification
45
     * @return string
46
     */
47 9
    private function renderNotification(Notification $notification)
48
    {
49 9
        $classNameSuffix = $this->getClassNameSuffix($notification->getType());
50
        return <<<HTML
51 9
<div class="alert alert-{$classNameSuffix}" role="alert">
52 9
    {$notification->getMessage()}
53
</div>
54
55 9
HTML;
56
    }
57
58
    /**
59
     * @param string $type
60
     * @return string
61
     */
62 9
    private function getClassNameSuffix($type)
63
    {
64 9
        if (!isset($this->classNameSuffixMap[$type])) {
65 3
            return 'default';
66
        }
67
68 6
        return $this->classNameSuffixMap[$type];
69
    }
70
}
71