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.
Passed
Push — master ( 354c7c...907f89 )
by Jamie
05:42
created

ArrayAccessTrait   C

Complexity

Total Complexity 57

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 57
c 2
b 1
f 1
lcom 1
cbo 0
dl 0
loc 58
rs 6.4331
ccs 13
cts 13
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 8 2
A offsetExists() 0 4 1
A offsetUnset() 0 4 1
A offsetGet() 0 4 2

How to fix   Complexity   

Complex Class

Complex classes like ArrayAccessTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ArrayAccessTrait, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace OpenStack\Common;
4
5
/**
6
 * Encapsulates common logic for classes which implement the SPL \ArrayAccess interface.
7
 *
8
 * @package OpenStack\Common
9
 */
10
trait ArrayAccessTrait
11
{
12
    /**
13
     * The internal state that this object represents
14
     *
15
     * @var array
16
     */
17
    private $internalState = [];
18
19
    /**
20
     * Sets an internal key with a value.
21
     *
22
     * @param string $offset
23
     * @param mixed  $value
24
     */
25 5
    public function offsetSet($offset, $value)
26
    {
27 5
        if (null === $offset) {
28 1
            $this->internalState[] = $value;
29 1
        } else {
30 4
            $this->internalState[$offset] = $value;
31
        }
32 5
    }
33
34
    /**
35
     * Checks whether an internal key exists.
36
     *
37
     * @param string $offset
38
     *
39
     * @return bool
40
     */
41 3
    public function offsetExists($offset)
42
    {
43 3
        return isset($this->internalState[$offset]);
44
    }
45
46
    /**
47
     * Unsets an internal key.
48
     *
49
     * @param string $offset
50
     */
51 1
    public function offsetUnset($offset)
52
    {
53 1
        unset($this->internalState[$offset]);
54 1
    }
55
56
    /**
57
     * Retrieves an internal key.
58
     *
59
     * @param string $offset
60
     *
61
     * @return mixed|null
62
     */
63 2
    public function offsetGet($offset)
64
    {
65 2
        return $this->offsetExists($offset) ? $this->internalState[$offset] : null;
66
    }
67
}
68