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   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setOption() 0 7 2
A generateOptions() 0 10 3
A checkJsonErrors() 0 6 2
A clearOptions() 0 5 1
A setOptions() 0 7 2
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
}