FlashMessage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 2
1
<?php
2
3
namespace DM\AjaxCom\Responder\Container;
4
5
class FlashMessage extends Container
6
{
7
    const TYPE_SUCCESS = 'success';
8
    const TYPE_INFO = 'info';
9
    const TYPE_ERROR = 'error';
10
    const METHOD_APPEND = 'append';
11
    const METHOD_REPLACE = 'replace';
12
13
    const OPTION_TYPE = 'type';
14
15
    private static $template = '<div class="%type%">%value%</div>';
16
17
    private static $container = '[data-ajaxcom-flashmessage]';
18
19
    public function __construct($message, $type = self::TYPE_SUCCESS, $method = self::METHOD_APPEND)
20
    {
21
        parent::__construct();
22
        $this->registerOption(self::OPTION_TYPE);
23
24
        $this->setOption(self::OPTION_TYPE, $type);
25
        $this->setOption(self::OPTION_TARGET, $this::$container);
26
27
        $value = $this::$template;
28
        $value = str_replace('%type%', $type, $value);
29
        $value = str_replace('%value%', $message, $value);
30
31
        if ($method == self::METHOD_APPEND) {
32
            $this->append($value);
33
        } else {
34
            $this->html($value);
35
        }
36
    }
37
}
38