TestResultDefinition::getFormatDefinitions()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 72

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 72
ccs 27
cts 27
cp 1
rs 8.6109
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Configuration\DependencyInjection;
6
7
use Paraunit\TestResult\TestResultContainer;
8
use Paraunit\TestResult\TestResultFactory;
9
use Paraunit\TestResult\TestResultFormat;
10
use Paraunit\TestResult\TestResultList;
11
use Paraunit\TestResult\TestResultWithSymbolFormat;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Definition;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
class TestResultDefinition
17
{
18 70
    public function configure(ContainerBuilder $container)
19
    {
20 70
        $container->setDefinition(TestResultFactory::class, new Definition(TestResultFactory::class));
21 70
        $this->configureTestResultContainer($container);
22
    }
23
24 70
    private function configureTestResultContainer(ContainerBuilder $container)
25
    {
26 70
        $testResultList = new Definition(TestResultList::class);
27
28 70
        foreach ($this->getFormatDefinitions() as $name => $format) {
29 70
            $formatName = sprintf('paraunit.test_result.%s_format', $name);
30 70
            $testResultContainerName = sprintf('paraunit.test_result.%s_container', $name);
31
32 70
            $container->setDefinition($formatName, $format);
33 70
            $container->setDefinition($testResultContainerName, new Definition(TestResultContainer::class, [
34 70
                new Reference($formatName),
35
            ]));
36
37 70
            $testResultList->addMethodCall('addContainer', [new Reference($testResultContainerName)]);
38
        }
39
40 70
        $container->setDefinition(TestResultList::class, $testResultList);
41
    }
42
43
    /**
44
     * @return Definition[]
45
     */
46 70
    private function getFormatDefinitions(): array
47
    {
48
        return [
49 70
            'unknown' => new Definition(TestResultWithSymbolFormat::class, [
50 70
                '?',
51
                'unknown',
52
                'unknown results (log parsing failed)',
53
            ]),
54 70
            'abnormal_terminated' => new Definition(TestResultWithSymbolFormat::class, [
55 70
                'X',
56
                'abnormal',
57
                'abnormal terminations (fatal errors, segfaults)',
58
            ]),
59 70
            'coverage_failure' => new Definition(TestResultFormat::class, [
60 70
                'error',
61
                'coverage not fetched',
62
            ]),
63 70
            'error' => new Definition(TestResultWithSymbolFormat::class, [
64 70
                'E',
65
                'error',
66
                'errors',
67
            ]),
68 70
            'failure' => new Definition(TestResultWithSymbolFormat::class, [
69 70
                'F',
70
                'fail',
71
                'failures',
72
            ]),
73 70
            'warning' => new Definition(TestResultWithSymbolFormat::class, [
74 70
                'W',
75
                'warning',
76
                'warnings',
77
            ]),
78 70
            'deprecation' => new Definition(TestResultFormat::class, [
79 70
                'fail',
80
                'deprecation warnings',
81
            ]),
82 70
            'no_test_executed' => new Definition(TestResultFormat::class, [
83 70
                'warning',
84
                'no tests executed',
85
            ]),
86 70
            'risky' => new Definition(TestResultWithSymbolFormat::class, [
87 70
                'R',
88
                'warning',
89
                'risky outcome',
90
            ]),
91 70
            'skipped' => new Definition(TestResultWithSymbolFormat::class, [
92 70
                'S',
93
                'skip',
94
                'skipped outcome',
95
                false,
96
            ]),
97 70
            'incomplete' => new Definition(TestResultWithSymbolFormat::class, [
98 70
                'I',
99
                'incomplete',
100
                'incomplete outcome',
101
                false,
102
            ]),
103 70
            'retry' => new Definition(TestResultWithSymbolFormat::class, [
104 70
                'A',
105
                'ok',
106
                'RETRIED',
107
                false,
108
            ]),
109 70
            'pass' => new Definition(TestResultWithSymbolFormat::class, [
110 70
                '.',
111
                'ok',
112
                'PASSED',
113
                false,
114
                false,
115
            ]),
116
        ];
117
    }
118
}
119