TestResultFactory::createFromLog()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.3222
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5
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 41
    public function createFromLog(\stdClass $log): PrintableTestResultInterface
17
    {
18 41
        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 35
        if (! property_exists($log, 'message')) {
26 5
            return new MuteTestResult();
27
        }
28
29 32
        if (property_exists($log, 'trace')) {
30 31
            return new FullTestResult($log->test, $log->message, $log->trace);
31
        }
32
33 1
        return new TestResultWithMessage($log->test, $log->message);
34
    }
35
}
36