Completed
Pull Request — develop (#27)
by Chris
01:54
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
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <https://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Chrisyue\PhpM3u8\Dumper;
13
14
use Chrisyue\PhpM3u8\Config;
15
16
class AttributeListDumper
17
{
18
    private $valueDumper;
19
20
    public function __construct(Config $valueDumper)
21
    {
22
        $this->valueDumper = $valueDumper;
23
    }
24
25
    public function dump(\ArrayObject $data, array $types)
26
    {
27
        $result = [];
28
        foreach ($data as $key => $value) {
29
            if (!isset($types[$key])) {
30
                continue;
31
            }
32
33
            $type = $types[$key];
34
            $dump = $this->valueDumper->get($type);
35
36
            $result[] = sprintf('%s=%s', $key, $dump($value));
37
        }
38
39
        if (!empty($result)) {
40
            return implode(',', $result);
41
        }
42
    }
43
}
44