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

CommandUtil   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A splitCommands() 0 26 6
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
}