Completed
Push — master ( 689084...daf696 )
by Joao
10s
created

BaseHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A option() 0 4 1
A writeHeader() 0 6 2
A writeOutput() 0 9 1
1
<?php
2
3
namespace ByJG\RestServer\HandleOutput;
4
5
use ByJG\RestServer\ServiceAbstract;
6
7
abstract class BaseHandler implements HandleOutputInterface
8
{
9
    protected $options = [
10
        'header' => [],
11
        'build-null' => true,
12
        'only-string' => false
13
    ];
14
15
    public function option($option, $value)
16
    {
17
        $this->options[$option] = $value;
18
    }
19
20
    public function writeHeader()
21
    {
22
        foreach ($this->options['header'] as $header) {
23
            header($header);
24
        }
25
    }
26
27
    public function writeOutput(ServiceAbstract $instance)
28
    {
29
        $serialized = $instance
30
            ->getResponse()
31
            ->getResponseBag()
32
            ->process($this->options['build-null'], $this->options['only-string']);
33
34
        return $this->getFormatter()->process($serialized);
35
    }
36
}
37