HtmlFormatter::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 7
nc 4
nop 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Shared
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Shared\Message\Formatter;
16
17
/**
18
 * Simple HTML formatter for message package
19
 *
20
 * @package Phossa2\Shared
21
 * @author  Hong Zhang <[email protected]>
22
 * @see     DefaultFormatter
23
 * @version 2.0.0
24
 * @since   2.0.0 added
25
 */
26
class HtmlFormatter extends DefaultFormatter
27
{
28
    /**
29
     * opening tag
30
     *
31
     * @var    string
32
     * @access protected
33
     */
34
    protected $openTag = '<span class="message">';
35
36
    /**
37
     * closing tag
38
     *
39
     * @var    string
40
     * @access protected
41
     */
42
    protected $closeTag = '</span>';
43
44
    /**
45
     * constructor
46
     *
47
     * @param  string $openTag opening tag
48
     * @param  string $closeTag closing tag
49
     * @access public
50
     */
51
    public function __construct(
52
        /*# string */ $openTag = '',
53
        /*# string */ $closeTag = ''
54
    ) {
55
        if ($openTag) {
56
            $this->openTag = $openTag;
57
        }
58
        if ($closeTag) {
59
            $this->closeTag = $closeTag;
60
        }
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    public function formatMessage(
67
        /*# string */ $template,
68
        array $arguments = []
69
    )/*# : string */ {
70
        $this->stringize($arguments)->matchTemplate($template, $arguments);
71
        return vsprintf(
72
            $this->openTag .
73
            str_replace('%s', '<b>%s</b>', $template) .
74
            $this->closeTag,
75
            $arguments
76
        );
77
    }
78
}
79