Completed
Pull Request — master (#116)
by Alessandro
08:37
created

TestResultFactory::addTraceToResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\TestResult;
6
7
use Paraunit\Parser\JSON\LogFetcher;
8
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
9
10
/**
11
 * Class TestResultFactory
12
 * @package Paraunit\TestResult
13
 */
14
class TestResultFactory
15
{
16 35
    public function createFromLog(\stdClass $log): PrintableTestResultInterface
17
    {
18 35
        if (property_exists($log, 'status') && $log->status === LogFetcher::LOG_ENDING_STATUS) {
19 13
            return new TestResultWithAbnormalTermination(
20 13
                $log->test,
21 13
                'Abnormal termination -- complete test output:'
22
            );
23
        }
24
25 29
        if (! property_exists($log, 'message')) {
26 5
            return new MuteTestResult();
27
        }
28
29 26
        if (property_exists($log, 'trace')) {
30 25
            return new FullTestResult($log->test, $log->message, $log->trace);
31
        }
32
33 1
        return new TestResultWithMessage($log->test, $log->message);
34
    }
35
}
36