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.

AbstractJson::setOptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * AbstractJson
4
 *
5
 * @author Kachit
6
 * @package Kachit\Helper\Json
7
 */
8
namespace Kachit\Helper\Json;
9
10
class AbstractJson
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $options = [];
16
17
    /**
18
     * Set encode value
19
     *
20
     * @param int $key
21
     * @param bool $value
22
     * @return $this
23
     */
24
    protected function setOption($key, $value)
25
    {
26
        if (array_key_exists($key, $this->options)) {
27
            $this->options[$key] = (bool)$value;
28
        }
29
        return $this;
30
    }
31
32
    /**
33
     * Generate options list
34
     *
35
     * @return int
36
     */
37
    protected function generateOptions()
38
    {
39
        $options = 0;
40
        foreach ($this->options as $option => $state) {
41
            if ($state) {
42
                $options = $options | $option;
43
            }
44
        }
45
        return $options;
46
    }
47
48
    /**
49
     * Check json encoding errors
50
     *
51
     * @throws \Exception
52
     */
53
    protected function checkJsonErrors()
54
    {
55
        if (json_last_error() !== JSON_ERROR_NONE) {
56
            throw new \Exception(json_last_error_msg());
57
        }
58
    }
59
60
    /**
61
     * Clear options
62
     *
63
     * @return $this
64
     */
65
    public function clearOptions()
66
    {
67
        $this->options = [];
68
        return $this;
69
    }
70
71
    /**
72
     * Set options
73
     *
74
     * @param array $options
75
     * @return $this
76
     */
77
    public function setOptions(array $options)
78
    {
79
        foreach ($options as $key) {
80
            $this->setOption($key, true);
81
        }
82
        return $this;
83
    }
84
}