Completed
Push — master ( 06164a...c7fa44 )
by Alessandro
04:05
created

OutputContainer::getFileNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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