Completed
Push — master ( 6a83c2...6c3c1b )
by Alessandro
04:16
created

WarningParser::parseAndContinue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 17
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 9
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Paraunit\Parser;
4
5
use Paraunit\Process\ProcessResultInterface;
6
7 View Code Duplication
class WarningParser implements ProcessOutputParserChainElementInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    const WARNING_REGEX = '/(?:There (?:was|were) \d+ warnings?:\n\n)((?:.|\n)+)(?:\n--|FAILURES|WARNINGS)/U';
10
11
    /**
12
     * @param ProcessResultInterface $process
13
     *
14
     * @return bool True if chain should continue
15
     */
16 12
    public function parseAndContinue(ProcessResultInterface $process)
17
    {
18 12
        $warningsBlob = array();
19 12
        preg_match(self::WARNING_REGEX, $process->getOutput(), $warningsBlob);
20
21 12
        if (isset($warningsBlob[1])) {
22 2
            $warnings = preg_split('/^\d+\) /m', $warningsBlob[1]);
23
            // il primo è sempre vuoto a causa dello split
24 2
            unset($warnings[0]);
25
26 2
            foreach ($warnings as $singleWarning) {
27 2
                $process->addWarning(trim($singleWarning));
28 2
            }
29 2
        }
30
31 12
        return true;
32
    }
33
}
34