Completed
Push — master ( a7faa2...c7788e )
by Christian
9s
created

JsonSerializer::serialize()   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 1
1
<?php
2
3
/**
4
 * Serializer for json.
5
 * @author Christian Blank <[email protected]>
6
 */
7
class JsonSerializer 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...
8
9
    /**
10
     * @config
11
     */
12
    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...
13
    
14
    /**
15
     * The content type.
16
     * @var string
17
     */
18
    private $contentType = "application/json";
19
20
    /**
21
     * Serializes the given data into a json string.
22
     *
23
     * @param array $data the data that should be serialized
24
     * @return string a json formatted string
25
     */
26
    public function serialize($data) {
27
        return json_encode($data, JSON_PRETTY_PRINT);
28
    }
29
30
    public function contentType() {
31
        return $this->contentType;
32
    }
33
34
    /**
35
     * Indicates if the serializer is active.
36
     * Serializers can be deactivated to use another implementation for the same mime type.
37
     *
38
     * @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...
39
     */
40
    public function active() {
41
        return $this->config()->get('is_active');
42
    }
43
}
44