FlashMessage::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 12
nc 2
nop 3
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