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

AttributeListDumper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A dump() 0 18 4
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