Completed
Pull Request — develop (#27)
by Chris
01:52
created

KvTransformer::doTransform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Transformer;
4
5
class KvTransformer extends AbstractTransformer
6
{
7
    public function supports($origin)
8
    {
9
        return is_string($origin) && preg_match('/^[A-Z][A-Z0-9]*=[^=]+/', $origin);
10
    }
11
12
    protected function doTransform($origin)
13
    {
14
        preg_match_all('/(?<=^|,)[A-Z0-9-]+=("?).+?\1(?=,|$)/', $origin, $matches);
15
16
        $result = [];
17
        foreach ($matches[0] as $attr) {
18
            list($name, $value) = explode('=', $attr);
19
            $result[$name] = $value;
20
        }
21
22
        return $result;
23
    }
24
}
25