Passed
Pull Request — master (#11)
by Joao
01:36
created

MockOutputProcessor::writeHeader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 14
ccs 0
cts 9
cp 0
crap 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace ByJG\RestServer\OutputProcessor;
4
5
use ByJG\RestServer\HttpResponse;
6
use ByJG\Serializer\Formatter\FormatterInterface;
7
use Whoops\Handler\Handler;
8
9
class MockOutputProcessor extends BaseOutputProcessor
10
{
11
    /**
12
     * @var OutputProcessorInterface
13
     */
14
    protected $originalOutputProcessor;
15
16
    public function __construct($class)
17
    {
18
        $this->originalOutputProcessor = new $class();
19
    }
20
21
    protected function writeHeader(HttpResponse $response)
22
    {
23
        echo "HTTP/1.1 " . $response->getResponseCode() . "\r\n";
24
        echo "Content-Type: " . $this->getContentType() . "\r\n";
25
26
        foreach ($response->getHeaders() as $header) {
27
            if (is_array($header)) {
28
                echo "${header[0]}: ${header[1]}\n";
29
                continue;
30
            }
31
            echo "$header\n";
32
        }
33
34
        echo "\r\n";
35
    }
36
37
    public function getContentType()
38
    {
39
        return $this->originalOutputProcessor->getContentType();
40
    }
41
42
43
    /**
44
     * @return void
45
     */
46
    public function writeContentType()
47
    {
48
        // Do nothing;
49
    }
50
51
52
    /**
53
     * @return Handler
54
     */
55
    public function getDetailedErrorHandler()
56
    {
57
        return $this->originalOutputProcessor->getDetailedErrorHandler();
58
    }
59
60
    /**
61
     * @return Handler
62
     */
63
    public function getErrorHandler()
64
    {
65
        return $this->originalOutputProcessor->getErrorHandler();
66
    }
67
68
69
    /**
70
     * @return FormatterInterface
71
     */
72
    public function getFormatter()
73
    {
74
        return $this->originalOutputProcessor->getFormatter();
75
    }
76
}
77