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

KvTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 20
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 2
A doTransform() 0 12 2
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