DeprecationParser::createTestResult()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Parser;
6
7
use Paraunit\Lifecycle\ProcessEvent;
8
use Paraunit\Process\AbstractParaunitProcess;
9
use Paraunit\TestResult\Interfaces\TestResultHandlerInterface;
10
use Paraunit\TestResult\TestResultWithMessage;
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12
13
class DeprecationParser implements EventSubscriberInterface
14
{
15
    /** @var TestResultHandlerInterface */
16
    private $testResultContainer;
17
18
    /**
19
     * DeprecationParser constructor.
20
     * @param TestResultHandlerInterface $testResultContainer
21
     */
22 35
    public function __construct(TestResultHandlerInterface $testResultContainer)
23
    {
24 35
        $this->testResultContainer = $testResultContainer;
25
    }
26
27 70
    public static function getSubscribedEvents(): array
28
    {
29
        return [
30 70
            ProcessEvent::PROCESS_PARSING_COMPLETED => 'handleDeprecations',
31
        ];
32
    }
33
34 35
    public function handleDeprecations(ProcessEvent $event)
35
    {
36 35
        $process = $event->getProcess();
37
38 35
        if ($process->getExitCode() === 0) {
39 24
            return;
40
        }
41
42 13
        if (strpos($process->getOutput(), 'deprecation') !== false) {
43 3
            $testResult = $this->createTestResult($process);
44 3
            $this->testResultContainer->handleTestResult($process, $testResult);
45
        }
46
    }
47
48 3
    private function createTestResult(AbstractParaunitProcess $process): TestResultWithMessage
49
    {
50 3
        return new TestResultWithMessage(
51 3
            $process->getTestClassName() ?? $process->getFilename(),
52 3
            $process->getOutput()
53
        );
54
    }
55
}
56