Completed
Pull Request — master (#37)
by Alessandro
02:23
created

OutputContainer::isEmptyMessage()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 8.8571
cc 5
eloc 9
nc 5
nop 1
crap 5
1
<?php
2
3
namespace Paraunit\Output;
4
5
use Paraunit\Process\ProcessWithResultsInterface;
6
7
/**
8
 * Class OutputContainer
9
 * @package Paraunit\Output
10
 */
11
class OutputContainer extends AbstractOutputContainer implements OutputContainerInterface
12
{
13
    /** @var string[][] */
14
    protected $outputBuffer;
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 11
    public function __construct($tag, $title, $singleResultMarker)
20
    {
21 11
        parent::__construct($tag, $title, $singleResultMarker);
22
23 11
        $this->outputBuffer = array();
24 11
    }
25
26
    /**
27
     * @param ProcessWithResultsInterface $process
28
     * @param string $message
29
     */
30 11
    public function addToOutputBuffer(ProcessWithResultsInterface $process, $message)
31
    {
32 11
        if ($this->isEmptyMessage($message)) {
33 8
            $this->addFileNameOnly($process);
34 8
        } else {
35 7
            $this->outputBuffer[$process->getFilename()][] = $message;
36
        }
37 11
    }
38
39
    /**
40
     * @param ProcessWithResultsInterface $process
41
     */
42 8
    private function addFileNameOnly(ProcessWithResultsInterface $process)
43
    {
44 8
        if ( ! array_key_exists($process->getFilename(), $this->outputBuffer)) {
45 4
            $this->outputBuffer[$process->getFilename()] = array();
46 4
        }
47 8
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getFileNames()
53
    {
54
        return array_keys($this->outputBuffer);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getOutputBuffer()
61
    {
62
        return $this->outputBuffer;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 11
    public function countFiles()
69
    {
70 11
        return count($this->outputBuffer);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 11
    public function countMessages()
77
    {
78 11
        $messageCount = 0;
79 11
        foreach ($this->outputBuffer as $fileName => $fileMessages) {
80 11
            $messageCount += count($fileMessages);
81 11
        }
82
83 11
        return $messageCount;
84
    }
85
86
    /**
87
     * @param string | null $message
88
     * @return bool
89
     */
90 11
    private function isEmptyMessage($message)
91
    {
92 11
        switch (mb_strtolower(trim($message))) {
93 11
            case null:
94 11
            case '':
95 11
            case 'skipped test:':
96 11
            case 'incomplete test:':
97 8
                return true;
98 7
            default:
99 7
                return false;
100
101 7
        }
102
    }
103
}
104