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

KeyValueWriter::array2String()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
rs 9.2
cc 4
eloc 8
nc 4
nop 3
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
}