Completed
Push — master ( 4ff2ad...4ba911 )
by Franck
03:40
created

AbstractOutput   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 34
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
encode() 0 1 ?
A getContentType() 0 8 2
1
<?php
2
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix\Output;
14
15
abstract class AbstractOutput
16
{
17
18
    /**
19
     * Holds the media-type .
20
     * @var string
21
     */
22
    protected $content_type = null;
23
24
    /**
25
     * Encode an array of data.
26
     *
27
     * @param  array       $data     Response data to encode
28
     * @param  string|null $rootNode The rootNode element.
29
     * @return string
30
     */
31
    abstract public function encode(array $data, $rootNode=null);
32
33
    /**
34
     * Returns the content-type.
35
     *
36
     * @return string
37
     * @throws \RuntimeException If self::contentType === null
38
     */
39
    public function getContentType()
40
    {
41
        if (null === $this->content_type) {
42
            throw new \RuntimeException('Missing a content-type.');
43
        }
44
45
        return $this->content_type;
46
    }
47
48
}
49