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

ProcessOutputParser::getParsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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