Completed
Pull Request — develop (#27)
by Chris
05:29
created

AttributeListDumper::dump()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 6
nop 2
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Dumper;
4
5
use Chrisyue\PhpM3u8\Config;
6
7
class AttributeListDumper
8
{
9
    private $valueDumper;
10
11
    public function __construct(Config $valueDumper)
12
    {
13
        $this->valueDumper = $valueDumper;
14
    }
15
16
    public function dump(\ArrayObject $data, array $types)
17
    {
18
        $result = [];
19
        foreach ($data as $key => $value) {
20
            if (!isset($types[$key])) {
21
                continue;
22
            }
23
24
            $type = $types[$key];
25
            $dump = $this->valueDumper->get($type);
26
27
            $result[] = sprintf('%s=%s', $key, $dump($value));
28
        }
29
30
        if (!empty($result)) {
31
            return implode(',', $result);
32
        }
33
    }
34
}
35