ArrayAccessTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 18.52 %

Importance

Changes 0
Metric Value
wmc 6
dl 10
loc 54
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 9 9 2
A offsetUnset() 0 5 1
A offsetGet() 0 3 2
A offsetExists() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Zurbaev\ApiClient\Traits;
4
5
/**
6
 * Trait ArrayAccessTrait
7
 *
8
 * @property array $data
9
 * @property array $keys
10
 */
11
trait ArrayAccessTrait
12
{
13
    /**
14
     * Determines if given offset exists in current collection.
15
     *
16
     * @param mixed $offset
17
     *
18
     * @return bool
19
     */
20
    public function offsetExists($offset)
21
    {
22
        return isset($this->data[$offset]);
23
    }
24
25
    /**
26
     * Puts value to given offset or appends it to current collection.
27
     *
28
     * @param mixed $offset
29
     * @param mixed $value
30
     */
31 View Code Duplication
    public function offsetSet($offset, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        if (is_null($offset)) {
34
            $this->data[] = $value;
35
        } else {
36
            $this->data[$offset] = $value;
37
        }
38
39
        $this->keys = array_keys($this->data);
40
    }
41
42
    /**
43
     * Retrieves given offset from current collection.
44
     * Returns NULL if no value found.
45
     *
46
     * @param mixed $offset
47
     *
48
     * @return mixed|null
49
     */
50
    public function offsetGet($offset)
51
    {
52
        return isset($this->data[$offset]) ? $this->data[$offset] : null;
53
    }
54
55
    /**
56
     * Drops given offset from current collection.
57
     *
58
     * @param mixed $offset
59
     */
60
    public function offsetUnset($offset)
61
    {
62
        unset($this->data[$offset]);
63
64
        $this->keys = array_keys($this->data);
65
    }
66
}
67