Completed
Push — output_parsers_refactor ( 9ffc6c...755930 )
by Alessandro
09:57
created

JSONLogParser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 95.12%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 11
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 65
ccs 39
cts 41
cp 0.9512
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addParser() 0 4 1
A parse() 0 8 2
A extractTestResult() 0 10 3
A checkErrorMessage() 0 13 4
1
<?php
2
3
namespace Paraunit\Parser;
4
5
use Paraunit\Exception\JSONLogNotFoundException;
6
use Paraunit\Exception\RecoverableTestErrorException;
7
use Paraunit\Process\ProcessResultInterface;
8
9
/**
10
 * Class JSONLogParser
11
 * @package Paraunit\Parser
12
 */
13
class JSONLogParser
14
{
15
    /** @var  JSONLogFetcher */
16
    private $logLocator;
17
18
    /** @var JSONParserChainElementInterface[] */
19
    protected $parsers;
20
21 10
    /**
22
     * JSONLogParser constructor.
23 10
     * @param JSONLogFetcher $logLocator
24 10
     */
25
    public function __construct(JSONLogFetcher $logLocator)
26 10
    {
27
        $this->logLocator = $logLocator;
28
        $this->parsers = array();
29 10
    }
30 10
31 1
    /**
32
     * @param JSONParserChainElementInterface $parser
33
     */
34 9
    public function addParser(JSONParserChainElementInterface $parser)
35 9
    {
36 9
        $this->parsers[] = $parser;
37
    }
38 9
39
    public function parse(ProcessResultInterface $process)
40
    {
41
        $logs = json_decode($this->logLocator->fetch($process));
0 ignored issues
show
Documentation introduced by
$process is of type object<Paraunit\Process\ProcessResultInterface>, but the function expects a object<Paraunit\Process\ParaunitProcessInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
43
        foreach ($logs as $singleLog) {
44
            $this->extractTestResult($process, $singleLog);
45 9
        }
46
    }
47 9
48 9
    /**
49 9
     * @param ProcessResultInterface $process
50 9
     * @param \stdClass $logItem
51 9
     * @return bool False if the parsing is still waiting for a test to give results
52 6
     */
53 1
    private function extractTestResult(ProcessResultInterface $process, \stdClass $logItem)
54 1
    {
55 6
        foreach ($this->parsers as $parser) {
56 5
            if ($parser->parsingFoundResult($process, $logItem)) {
57 5
                return true;
58 1
            }
59 1
        }
60 1
61
        return false;
62
    }
63 9
64 9
    private function checkErrorMessage(\stdClass $logItem)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
65 9
    {
66
        switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^Incomplete... /', $logItem->message) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^Skipped Te... /', $logItem->message) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^Risky Test: /', $logItem->message) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
67 5
            case preg_match('/^Incomplete Test: /', $logItem->message):
68
                return 'I';
69 5
            case preg_match('/^Skipped Test: /', $logItem->message):
70 5
                return 'S';
71 1
            case preg_match('/^Risky Test: /', $logItem->message):
72 4
                return 'R';
73 1
            default:
74 3
                return 'E';
75 1
        }
76 2
    }
77
}
78