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

MockOutputProcessor   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 31.58%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 67
ccs 6
cts 19
cp 0.3158
rs 10
c 1
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentType() 0 3 1
A getFormatter() 0 3 1
A getDetailedErrorHandler() 0 3 1
A writeContentType() 0 2 1
A __construct() 0 3 1
A getErrorHandler() 0 3 1
A writeHeader() 0 15 4
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