Parser::parseContents()   A
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 14
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 29
rs 9.4888
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Patch\File\Header;
7
8
class Parser
9
{
10
    public function parseContents($header)
11
    {
12
        $lines = explode(PHP_EOL, $header);
13
14
        $key = 'label';
15
16
        $data = array();
17
18
        foreach ($lines as $line) {
19
            if (strpos($line, '@') === 0) {
20
                $tag = strstr($line, ' ', true);
21
22
                if (!$tag) {
23
                    $tag = $line;
24
                }
25
26
                $key = ltrim($tag, '@');
27
28
                $line = ltrim(strstr($line, ' '), ' ');
29
            }
30
31
            if (!isset($data[$key])) {
32
                $data[$key] = array();
33
            }
34
35
            $data[$key][] = $line;
36
        }
37
38
        return array_diff_key($data, array(''));
39
    }
40
}
41