Completed
Push — develop ( 034857...1b157a )
by Christian
8s
created

YamlSerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A contentType() 0 3 1
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