Processor   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
B process() 0 30 8
A getStorage() 0 4 1
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2017-02-01
5
 */
6
namespace Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Processor;
7
8
use JonasRudolph\PHPComponents\StringUtility\Implementation\StringUtility;
9
use Net\Bazzline\Component\ApacheServerStatusParser\Service\Content\Storage\StorageInterface;
10
use Net\Bazzline\Component\ApacheServerStatusParser\Service\StateMachine\SectionStateMachine;
11
12
class Processor
13
{
14
    /** @var SectionStateMachine */
15
    private $stateMachine;
16
17
    /** @var StringUtility */
18
    private $stringUtility;
19
20
    /** @var StorageInterface */
21
    private $storage;
22
23
    /**
24
     * Parser constructor.
25
     *
26
     * @param SectionStateMachine $stateMachine
27
     * @param StringUtility $stringUtility
28
     * @param StorageInterface $storage
29
     */
30
    public function __construct(
31
        SectionStateMachine $stateMachine,
32
        StringUtility $stringUtility,
33
        StorageInterface $storage
34
    ) {
35
        $storage->clear();
36
        $stateMachine->reset();
37
38
        $this->stateMachine     = $stateMachine;
39
        $this->stringUtility    = $stringUtility;
40
        $this->storage          = $storage;
41
    }
42
43
    /**
44
     * @param string $line
45
     */
46
    public function process($line)
47
    {
48
        //begin of dependencies
49
        $stateMachine   = $this->stateMachine;
50
        $stringUtility  = $this->stringUtility;
51
        $storage        = $this->storage;
52
        //end of dependencies
53
54
        //begin of business logic
55
        if ($stringUtility->startsWith($line, 'Current Time:')) {
56
            $stateMachine->setCurrentStateToStatistic();
57
        } else if ($stringUtility->startsWith($line, 'Server Details')) {
58
            $stateMachine->setCurrentStateToDetail();
59
        }
60
61
        if ($stateMachine->theCurrentStateIsDetail()) {
62
            $storage->addDetail($line);
63
        } else if ($stateMachine->theCurrentStateIsInformation()) {
64
            $storage->addInformation($line);
65
        } else if ($stateMachine->theCurrentStateIsScoreboard()) {
66
            $storage->addScoreboard($line);
67
        } else if ($stateMachine->theCurrentStateIsStatistic()) {
68
            $storage->addStatistic($line);
69
        }
70
71
        if ($stringUtility->contains($line, 'requests currently being processed')) {
72
            $stateMachine->setCurrentStateToScoreboard();
73
        }
74
        //end of business logic
75
    }
76
77
    /**
78
     * @return StorageInterface
79
     */
80
    public function getStorage()
81
    {
82
        return $this->storage;
83
    }
84
}
85