FilesRecapPrinter::printFileRecap()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 17
cts 17
cp 1
rs 9.488
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Printer;
6
7
use Paraunit\Lifecycle\EngineEvent;
8
use Paraunit\TestResult\Interfaces\TestResultContainerInterface;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
/**
12
 * Class FilesRecapPrinter
13
 * @package Paraunit\Printer
14
 */
15
class FilesRecapPrinter extends AbstractFinalPrinter implements EventSubscriberInterface
16
{
17 70
    public static function getSubscribedEvents(): array
18
    {
19
        return [
20 70
            EngineEvent::END => ['onEngineEnd', 100],
21
        ];
22
    }
23
24 25
    public function onEngineEnd()
25
    {
26 25
        foreach ($this->testResultList->getTestResultContainers() as $parser) {
27 25
            $this->printFileRecap($parser);
28
        }
29
    }
30
31
    /**
32
     * @param TestResultContainerInterface $testResultContainer
33
     */
34 25
    private function printFileRecap(TestResultContainerInterface $testResultContainer)
35
    {
36 25
        if (! $testResultContainer->getTestResultFormat()->shouldPrintFilesRecap()) {
37 25
            return;
38
        }
39
40 25
        $filenames = $testResultContainer->getFileNames();
41
42 25
        if (count($filenames)) {
43 16
            $tag = $testResultContainer->getTestResultFormat()->getTag();
44 16
            $title = $testResultContainer->getTestResultFormat()->getTitle();
45 16
            $this->getOutput()->writeln('');
46 16
            $this->getOutput()->writeln(
47 16
                sprintf(
48 16
                    '<%s>%d files with %s:</%s>',
49 16
                    $tag,
50 16
                    count($filenames),
51 16
                    strtoupper($title),
52 16
                    $tag
53
                )
54
            );
55
56 16
            foreach ($filenames as $fileName) {
57 16
                $this->getOutput()->writeln(sprintf(' <%s>%s</%s>', $tag, $fileName, $tag));
58
            }
59
        }
60
    }
61
}
62