LazyArrayAccess::offsetExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Zurbaev\ApiClient\Traits;
4
5
/**
6
 * Trait LazyArrayAccess
7
 *
8
 * @property array $items
9
 * @property array $keys
10
 */
11
trait LazyArrayAccess
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
        $this->checkLazyLoad();
0 ignored issues
show
Bug introduced by
It seems like checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $this->/** @scrutinizer ignore-call */ checkLazyLoad();
Loading history...
23
24
        return isset($this->items[$offset]);
25
    }
26
27
    /**
28
     * Puts value to given offset or appends it to current collection.
29
     *
30
     * @param mixed $offset
31
     * @param mixed $value
32
     */
33 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...
34
    {
35
        $this->checkLazyLoad();
0 ignored issues
show
Bug introduced by
It seems like checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $this->/** @scrutinizer ignore-call */ checkLazyLoad();
Loading history...
36
37
        if (is_null($offset)) {
38
            $this->items[] = $value;
39
        } else {
40
            $this->items[$offset] = $value;
41
        }
42
43
        $this->keys = array_keys($this->items);
44
    }
45
46
    /**
47
     * Retrieves given offset from current collection.
48
     * Returns NULL if no value found.
49
     *
50
     * @param mixed $offset
51
     *
52
     * @return mixed|null
53
     */
54
    public function offsetGet($offset)
55
    {
56
        $this->checkLazyLoad();
0 ignored issues
show
Bug introduced by
It seems like checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $this->/** @scrutinizer ignore-call */ checkLazyLoad();
Loading history...
57
58
        return isset($this->items[$offset]) ? $this->items[$offset] : null;
59
    }
60
61
    /**
62
     * Drops given offset from current collection.
63
     *
64
     * @param mixed $offset
65
     */
66
    public function offsetUnset($offset)
67
    {
68
        $this->checkLazyLoad();
0 ignored issues
show
Bug introduced by
It seems like checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $this->/** @scrutinizer ignore-call */ checkLazyLoad();
Loading history...
69
70
        unset($this->items[$offset]);
71
72
        $this->keys = array_keys($this->items);
73
    }
74
}
75