MockOutputProcessor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 57
ccs 0
cts 31
cp 0
rs 10
c 1
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentType() 0 3 1
A getFormatter() 0 3 1
A writeContentType() 0 2 1
A __construct() 0 3 1
A getErrorHandler() 0 3 1
A writeHeader() 0 14 3
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 getErrorHandler()
56
    {
57
        return $this->originalOutputProcessor->getErrorHandler();
58
    }
59
60
    /**
61
     * @return FormatterInterface
62
     */
63
    public function getFormatter()
64
    {
65
        return $this->originalOutputProcessor->getFormatter();
66
    }
67
}
68