Completed
Push — master ( f56f72...05a1a2 )
by Nikola
02:11
created

BaseWidget::htmlAttribsToString()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 12
nc 5
nop 1
1
<?php
2
/**
3
 * This file is part of the Disqus Helper package.
4
 *
5
 * Copyright (c) Nikola Posa <[email protected]>
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
namespace DisqusHelper\Widget;
12
13
/**
14
 * @author Nikola Posa <[email protected]>
15
 */
16
abstract class BaseWidget implements WidgetInterface
17
{
18
    protected function htmlAttribsToString(array $attribs) : string
19
    {
20
        $html = '';
21
22
        foreach ($attribs as $key => $val) {
23
            $key = htmlspecialchars($key, ENT_QUOTES);
24
25
            if (is_array($val)) {
26
                $val = implode(' ', $val);
27
            }
28
29
            if (strpos($val, '"') !== false) {
30
                $html .= "$key='$val' ";
31
            } else {
32
                $html .= "$key=\"$val\" ";
33
            }
34
        }
35
36
        $html = rtrim($html);
37
38
        return $html;
39
    }
40
}
41