Completed
Pull Request — master (#37)
by Alessandro
02:23
created

TestResultFactory::addTraceToResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Paraunit\TestResult;
4
5
use Paraunit\Parser\JSONLogFetcher;
6
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
7
8
/**
9
 * Class TestResultFactory
10
 * @package Paraunit\TestResult
11
 */
12
class TestResultFactory
13
{
14
    /** @var  TestResultFormat */
15
    private $format;
16
17
    /**
18
     * TestResultFactory constructor.
19
     * @param TestResultFormat $format
20
     */
21 41
    public function __construct(TestResultFormat $format)
22
    {
23 41
        $this->format = $format;
24 41
    }
25
26
    /**
27
     * @param \stdClass $log
28
     * @return PrintableTestResultInterface
29
     */
30 26
    public function createFromLog(\stdClass $log)
31
    {
32 26
        if (property_exists($log, 'status') && $log->status == JSONLogFetcher::LOG_ENDING_STATUS) {
33 8
            return new TestResultWithAbnormalTermination($this->format, $log->test, 'Abnormal termination -- complete test output:');
34
        }
35
36 22
        if ( ! property_exists($log, 'message')) {
37 4
            return new MuteTestResult($this->format);
0 ignored issues
show
Unused Code introduced by
The call to MuteTestResult::__construct() has too many arguments starting with $this->format.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
39
        }
40
41 19
        if (property_exists($log, 'trace')) {
42 18
            $result = new FullTestResult($this->format, $log->test, $log->message);
43 18
            $this->addTraceToResult($result, $log);
44
45 18
            return $result;
46
        }
47
48 1
        return new TestResultWithMessage($this->format, $log->test, $log->message);
49
    }
50
51
    /**
52
     * @param FullTestResult $result
53
     * @param \stdClass $log
54
     */
55 18
    private function addTraceToResult(FullTestResult $result, $log)
56
    {
57 18
        foreach ($log->trace as $traceStep) {
58 10
            $result->addTraceStep(new TraceStep($traceStep->file, $traceStep->line));
59 18
        }
60 18
    }
61
}
62