GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Encoder   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

12 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 7 1
A enableHexTag() 0 4 1
A enablePrettyPrint() 0 4 1
A enableBigIntAsString() 0 4 1
A enableUnescapedSlashes() 0 4 1
A enableUnescapedUnicode() 0 4 1
A enableHexAmp() 0 4 1
A enableHexApos() 0 4 1
A enableHexQuot() 0 4 1
A enableForceObject() 0 4 1
A enableNumericCheck() 0 4 1
A prepareValueForEncode() 0 7 3
1
<?php
2
/**
3
 * Encoder
4
 *
5
 * @author Kachit
6
 */
7
namespace Kachit\Helper\Json;
8
9
class Encoder extends AbstractJson
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $options = [
15
        JSON_HEX_TAG => false,
16
        JSON_HEX_AMP => false,
17
        JSON_HEX_APOS => false,
18
        JSON_HEX_QUOT => false,
19
        JSON_FORCE_OBJECT => false,
20
        JSON_NUMERIC_CHECK => false,
21
        //php 5.4 support
22
        JSON_BIGINT_AS_STRING => false,
23
        JSON_PRETTY_PRINT => false,
24
        JSON_UNESCAPED_SLASHES => true,
25
        JSON_UNESCAPED_UNICODE => true,
26
    ];
27
28
    /**
29
     * Encode value to json string
30
     *
31
     * @param mixed $value
32
     * @return string
33
     */
34
    public function encode($value)
35
    {
36
        $value = $this->prepareValueForEncode($value);
37
        $jsonString = json_encode($value, $this->generateOptions());
38
        $this->checkJsonErrors();
39
        return $jsonString;
40
    }
41
42
    /**
43
     * Set encode option JSON_HEX_TAG
44
     *
45
     * @param bool $value
46
     * @return $this
47
     */
48
    public function enableHexTag($value = true)
49
    {
50
        return $this->setOption(JSON_HEX_TAG, $value);
51
    }
52
53
    /**
54
     * Set encode option JSON_PRETTY_PRINT
55
     *
56
     * @param bool $value
57
     * @return $this
58
     */
59
    public function enablePrettyPrint($value = true)
60
    {
61
        return $this->setOption(JSON_PRETTY_PRINT, $value);
62
    }
63
64
    /**
65
     * Set encode option JSON_BIGINT_AS_STRING
66
     *
67
     * @param bool $value
68
     * @return $this
69
     */
70
    public function enableBigIntAsString($value = true)
71
    {
72
        return $this->setOption(JSON_BIGINT_AS_STRING, $value);
73
    }
74
75
    /**
76
     * Set encode option JSON_UNESCAPED_SLASHES
77
     *
78
     * @param bool $value
79
     * @return $this
80
     */
81
    public function enableUnescapedSlashes($value = true)
82
    {
83
        return $this->setOption(JSON_UNESCAPED_SLASHES, $value);
84
    }
85
86
    /**
87
     * Set encode option JSON_UNESCAPED_UNICODE
88
     *
89
     * @param bool $value
90
     * @return $this
91
     */
92
    public function enableUnescapedUnicode($value = true)
93
    {
94
        return $this->setOption(JSON_UNESCAPED_UNICODE, $value);
95
    }
96
97
    /**
98
     * Set encode option JSON_HEX_AMP
99
     *
100
     * @param bool $value
101
     * @return $this
102
     */
103
    public function enableHexAmp($value = true)
104
    {
105
        return $this->setOption(JSON_HEX_AMP, $value);
106
    }
107
108
    /**
109
     * Set encode option JSON_HEX_APOS
110
     *
111
     * @param bool $value
112
     * @return $this
113
     */
114
    public function enableHexApos($value = true)
115
    {
116
        return $this->setOption(JSON_HEX_APOS, $value);
117
    }
118
119
    /**
120
     * Set encode option JSON_HEX_QUOT
121
     *
122
     * @param bool $value
123
     * @return $this
124
     */
125
    public function enableHexQuot($value = true)
126
    {
127
        return $this->setOption(JSON_HEX_QUOT, $value);
128
    }
129
130
    /**
131
     * Set encode option JSON_FORCE_OBJECT
132
     *
133
     * @param bool $value
134
     * @return $this
135
     */
136
    public function enableForceObject($value = true)
137
    {
138
        return $this->setOption(JSON_FORCE_OBJECT, $value);
139
    }
140
141
    /**
142
     * Set encode option JSON_NUMERIC_CHECK
143
     *
144
     * @param bool $value
145
     * @return $this
146
     */
147
    public function enableNumericCheck($value = true)
148
    {
149
        return $this->setOption(JSON_NUMERIC_CHECK, $value);
150
    }
151
152
    /**
153
     * Prepare value for encode
154
     *
155
     * @param mixed $value
156
     * @return array
157
     */
158
    protected function prepareValueForEncode($value)
159
    {
160
        if (!is_array($value) || !is_object($value)) {
161
            $value = (array)$value;
162
        }
163
        return $value;
164
    }
165
}