Issues (13)

src/Traits/ArrayAccessTrait.php (1 issue)

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
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