Completed
Push — master ( 4d3ebd...dc2236 )
by Edgar
03:41
created

KeyValueWriter::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
1
<?php
2
namespace nstdio\svg\util;
3
4
use nstdio\svg\XMLDocumentInterface;
5
6
/**
7
 * Class KeyValueWriter
8
 *
9
 * @package nstdio\svg\util
10
 * @author  Edgar Asatryan <[email protected]>
11
 */
12
class KeyValueWriter
13
{
14
    public static function apply(XMLDocumentInterface $element, array $attributes)
15
    {
16
        foreach ($attributes as $key => $value) {
17
            $element->setAttribute($key, $value);
18
        }
19
    }
20
21
    public static function styleArrayToString(array $input)
22
    {
23
        return self::array2String($input, ':', ';');
24
    }
25
26
    public static function array2String(array $input, $keyValueDelimiter, $valueEndDelimiter)
27
    {
28
        $ret = '';
29
        foreach ($input as $key => $value) {
30
            if (is_array($value)) {
31
                $ret .= self::array2String($value, $keyValueDelimiter, $valueEndDelimiter);
32
            } elseif ($key) {
33
                $ret .= $key . $keyValueDelimiter . $value . $valueEndDelimiter;
34
35
            }
36
        }
37
38
        return $ret;
39
    }
40
}