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

WarningParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 27
loc 27
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseAndContinue() 17 17 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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