Completed
Push — master ( 8844e1...b4c347 )
by Christian
04:21 queued 02:03
created

YamlSerializer::contentType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
use Symfony\Component\Yaml\Dumper;
6
7
/**
8
 * Serializer for yaml.
9
 * @author Christian Blank <[email protected]>
10
 */
11
class YamlSerializer extends \Object implements IRestSerializer {
12
13
    /**
14
     * @config
15
     */
16
    private static $is_active = true;
0 ignored issues
show
Unused Code introduced by
The property $is_active is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
    
18
    /**
19
     * The content type.
20
     * @var string
21
     */
22
    private $contentType = "application/yaml";
23
24
    /**
25
     * Serializes the given data into a yaml string.
26
     *
27
     * @param array $data the data that should be serialized
28
     * @return string a yaml formatted string
29
     */
30
    public function serialize($data) {
31
        $yamlDumper = new Dumper();
32
        return $yamlDumper->dump($data, 5);
33
    }
34
35
    public function contentType() {
36
        return $this->contentType;
37
    }
38
39
    /**
40
     * Indicates if the serializer is active.
41
     * Serializers can be deactivated to use another implementation for the same mime type.
42
     *
43
     * @return boolean
44
     */
45
    public function active() {
46
        return $this->config()->get('is_active');
47
    }
48
}
49