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

MockOutputProcessor::getDetailedErrorHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
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 3
    public function __construct($class)
17
    {
18 3
        $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 => $value) {
27
            if (is_array($value)) {
28
                foreach ($value as $headerValue) {
29
                    echo "$header: $headerValue\r\n";
30
                }
31
            } else {
32
                echo "$header: $value\r\n";
33
            }
34
        }
35
        echo "\r\n";
36
    }
37
38
    public function getContentType()
39
    {
40
        return $this->originalOutputProcessor->getContentType();
41
    }
42
43
44
    /**
45
     * @return void
46
     */
47
    public function writeContentType()
48
    {
49
        // Do nothing;
50
    }
51
52
53
    /**
54
     * @return Handler
55
     */
56
    public function getDetailedErrorHandler()
57
    {
58
        return $this->originalOutputProcessor->getDetailedErrorHandler();
59
    }
60
61
    /**
62
     * @return Handler
63
     */
64 3
    public function getErrorHandler()
65
    {
66 3
        return $this->originalOutputProcessor->getErrorHandler();
67
    }
68
69
70
    /**
71
     * @return FormatterInterface
72
     */
73 2
    public function getFormatter()
74
    {
75 2
        return $this->originalOutputProcessor->getFormatter();
76
    }
77
}
78