ScoreboardListOfLineParser   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 46 7
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2017-04-07
5
 */
6
7
namespace Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Parser;
8
9
use InvalidArgumentException;
10
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\Scoreboard;
11
12
class ScoreboardListOfLineParser implements ListOfLineParserInterface
13
{
14
    /**
15
     * @param string[] $listOfLine
16
     *
17
     * @return mixed
18
     * @throws InvalidArgumentException
19
     */
20
    public function parse(array $listOfLine)
21
    {
22
        //begin of business logic
23
        $listOfLineHasMinimalSize = (count($listOfLine) > 12);
24
25
        if ($listOfLineHasMinimalSize) {
26
            $collectListOfLegend        = false;
27
            $listOMandatoryProperties   = [
28
                'list_of_legend'    => [],
29
                'line_of_process'   => ''
30
            ];
31
32
            foreach ($listOfLine as $line) {
33
                if ($collectListOfLegend) {
34
                    $listOMandatoryProperties['list_of_legend'][] = $line;
35
                } else {
36
                    if ($line === 'Scoreboard Key:') {
37
                        $collectListOfLegend = true;
38
                    } else {
39
                        $listOMandatoryProperties['line_of_process'] .= $line;
40
                    }
41
                }
42
            }
43
44
            foreach ($listOMandatoryProperties as $name => $mandatoryProperty) {
45
                if (empty($mandatoryProperty)) {
46
                    throw new InvalidArgumentException(
47
                        'could not find mandatory property "' . $name . '"'
48
                    );
49
                }
50
            }
51
52
            $scoreboard = new Scoreboard(
53
                $listOMandatoryProperties['line_of_process'],
54
                $listOMandatoryProperties['list_of_legend']
55
            );
56
        } else {
57
            throw new InvalidArgumentException(
58
                self::class . ' can not parse given list of line "'
59
                . implode(',', $listOfLine) . '"'
60
            );
61
        }
62
63
        return $scoreboard;
64
        //end of business logic
65
    }
66
}
67