Completed
Push — master ( 83aeed...e335a8 )
by Alessandro
05:08
created

FailuresPrinter   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 19.3 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 6
dl 11
loc 57
ccs 35
cts 35
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onEngineEnd() 11 11 3
C printFailuresOutput() 0 36 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Paraunit\Printer;
4
5
use Paraunit\Lifecycle\EngineEvent;
6
use Paraunit\TestResult\Interfaces\FailureMessageInterface;
7
use Paraunit\TestResult\Interfaces\FunctionNameInterface;
8
use Paraunit\TestResult\Interfaces\StackTraceInterface;
9
use Paraunit\TestResult\TestResultContainer;
10
11
/**
12
 * Class FailuresPrinter
13
 * @package Paraunit\Printer
14
 */
15
class FailuresPrinter extends AbstractFinalPrinter
16
{
17
    /**
18
     * @param EngineEvent $engineEvent
19
     */
20 10 View Code Duplication
    public function onEngineEnd(EngineEvent $engineEvent)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22 10
        $this->output = $engineEvent->getOutputInterface();
23
        /** @var \DateInterval $elapsedTime */
24
25 10
        foreach ($this->logParser->getParsersForPrinting() as $parser) {
26 10
            if ($parser instanceof TestResultContainer) {
27 10
                $this->printFailuresOutput($parser);
28 10
            }
29 10
        }
30 10
    }
31
32
    /**
33
     * @param TestResultContainer $testResultContainer
34
     */
35 10
    private function printFailuresOutput(TestResultContainer $testResultContainer)
36
    {
37 10
        if ( ! $testResultContainer->getTestResultFormat()->shouldPrintTestOutput()) {
38 10
            return;
39
        }
40
41 10
        $tag = $testResultContainer->getTestResultFormat()->getTag();
42 10
        $title = $testResultContainer->getTestResultFormat()->getTitle();
43 10
        $i = 1;
44
45 10
        foreach ($testResultContainer->getTestResults() as $testResult) {
46 9
            if ($i == 1) {
47 9
                $this->output->writeln('');
48 9
                $this->output->writeln(sprintf('<%s>%s output:</%s>', $tag, ucwords($title), $tag));
49 9
            }
50
51 9
            $this->output->writeln('');
52 9
            $this->output->write(sprintf('<%s>%d) ', $tag, $i++));
53
54 9
            if ($testResult instanceof FunctionNameInterface) {
55 9
                $this->output->writeln($testResult->getFunctionName());
56 9
            }
57
58 9
            $this->output->write(sprintf('</%s>', $tag));
59
60 9
            if ($testResult instanceof FailureMessageInterface) {
61 9
                $this->output->writeln($testResult->getFailureMessage());
62 9
            }
63
64 9
            if ($testResult instanceof StackTraceInterface) {
65 6
                foreach ($testResult->getTrace() as $traceStep) {
66 5
                    $this->output->writeln((string)$traceStep);
67 6
                }
68 6
            }
69 10
        }
70 10
    }
71
}
72