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

AbstractOutput::getContentType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
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