Completed
Push — develop ( a3939b...aae45c )
by Christian
02:23
created

YamlSerializer::active()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
use Symfony\Component\Yaml\Dumper;
3
4
/**
5
 * Serializer for yaml.
6
 * @author Christian Blank <[email protected]>
7
 */
8
class YamlSerializer extends Object implements IRestSerializer {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
    /**
11
     * @config
12
     */
13
    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...
14
    
15
    /**
16
     * The content type.
17
     * @var string
18
     */
19
    private $contentType = "application/yaml";
20
21
    /**
22
     * Serializes the given data into a yaml string.
23
     *
24
     * @param array $data the data that should be serialized
25
     * @return string a yaml formatted string
26
     */
27
    public function serialize($data) {
28
        $yamlDumper = new Dumper();
29
        return $yamlDumper->dump($data, 5);
30
    }
31
32
    public function contentType() {
33
        return $this->contentType;
34
    }
35
36
    /**
37
     * Indicates if the serializer is active.
38
     * Serializers can be deactivated to use another implementation for the same mime type.
39
     *
40
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
41
     */
42
    public function active() {
43
        return $this->config()->get('is_active');
44
    }
45
}
46