Passed
Push — master ( f7ab1f...6a3297 )
by Nils
02:29
created

CommandUtil::splitCommands()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
c 1
b 0
f 0
nc 10
nop 1
dl 0
loc 26
rs 9.2222
1
<?php
2
3
namespace Startwind\Inventorio\Util;
4
5
abstract class CommandUtil
6
{
7
    public static function splitCommands(string $input): array
8
    {
9
        $lines = explode("\n", $input);
10
        $commands = [];
11
        $current = '';
12
13
        foreach ($lines as $line) {
14
            if (trim($line) === '') {
15
                continue;
16
            }
17
18
            if (preg_match('/^\s+/', $line)) {
19
                $current .= "\n" . $line;
20
            } else {
21
                if ($current !== '') {
22
                    $commands[] = trim($current);
23
                }
24
                $current = $line;
25
            }
26
        }
27
28
        if ($current !== '') {
29
            $commands[] = trim($current);
30
        }
31
32
        return $commands;
33
    }
34
35
}