ArrayAccessTrait::offsetUnset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib\Traits;
7
8
trait ArrayAccessTrait
9
{
10
    /**
11
     * Returns true when a key exists of the same type and value as $OFFSET
12
     *
13
     * @param mixed $offset
14
     * @return bool
15
     */
16 1 View Code Duplication
    public function offsetExists($offset)
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...
17
    {
18 1
        if ($this instanceof \Traversable) {
19 1
            foreach ($this as $key => $_) {
20 1
                if ($key === $offset) {
21 1
                    return true;
22
                }
23
            }
24
        }
25 1
        return false;
26
    }
27
28
    /**
29
     * Returns the value of a key with the same type and value as $OFFSET, or returns
30
     * $DEFAULT when it this key does not exist
31
     *
32
     * @param mixed $offset
33
     * @param mixed $default
34
     * @return mixed
35
     */
36 2 View Code Duplication
    public function offsetGet($offset, $default = null)
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...
37
    {
38 2
        if ($this instanceof \Traversable) {
39 1
            foreach ($this as $key => $value) {
40 1
                if ($key === $offset) {
41 1
                    return $value;
42
                }
43
            }
44
        }
45 2
        return $default;
46
    }
47
48
    /**
49
     * Not implemented
50
     *
51
     * @param mixed $offset
52
     * @param mixed $value
53
     */
54 1
    public function offsetSet($offset, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56 1
        throw new \RuntimeException('It is not possible to set iterator values');
57
    }
58
59
    /**
60
     * Not implemented
61
     *
62
     * @param mixed $offset
63
     */
64 1
    public function offsetUnset($offset)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66 1
        throw new \RuntimeException('It is not possible to unset iterator values');
67
    }
68
}
69