Completed
Branch output_parsers_refactor (69b7d7)
by Alessandro
02:50
created

ProcessOutputParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 6
c 6
b 1
f 1
lcom 1
cbo 2
dl 0
loc 38
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addParser() 0 4 1
A getParsers() 0 4 1
A onProcessTerminated() 0 8 3
1
<?php
2
3
namespace Paraunit\Parser;
4
5
use Paraunit\Lifecycle\ProcessEvent;
6
7
/**
8
 * Class ProcessOutputParser.
9
 */
10
class ProcessOutputParser
11
{
12
    /** @var ProcessOutputParserChainElementInterface[] */
13
    protected $parsers;
14
15 7
    public function __construct()
16
    {
17 7
        $this->parsers = array();
18 7
    }
19
20
    /**
21
     * @param ProcessOutputParserChainElementInterface $parser
22
     */
23 7
    public function addParser(ProcessOutputParserChainElementInterface $parser)
24
    {
25 7
        $this->parsers[] = $parser;
26 7
    }
27
28
    /**
29
     * @return ProcessOutputParserChainElementInterface[]
30
     */
31 7
    public function getParsers()
32
    {
33 7
        return $this->parsers;
34
    }
35
36
    /**
37
     * @param ProcessEvent $processEvent
38
     */
39 7
    public function onProcessTerminated(ProcessEvent $processEvent)
40
    {
41 7
        foreach ($this->parsers as $parser) {
42 7
            if ( ! $parser->parseAndContinue($processEvent->getProcess())) {
43 5
                return;
44
            }
45 7
        }
46 5
    }
47
}
48