Passed
Pull Request — master (#19)
by
unknown
03:59
created

ArrayAccessTrait::offsetGet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.6666
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib\Traits;
8
9
trait ArrayAccessTrait
10
{
11
    /**
12
     * Returns true when a key exists of the same type and value as $OFFSET
13
     *
14
     * @param mixed $offset
15
     * @return bool
16
     */
17 1
    public function offsetExists($offset)
18
    {
19 1
        foreach ($this as $key => $_) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Zicht\Itertools\lib\Traits\ArrayAccessTrait> is not traversable.
Loading history...
20 1
            if ($key === $offset) {
21 1
                return true;
22
            }
23
        }
24 1
        return false;
25
    }
26
27
    /**
28
     * Returns the value of a key with the same type and value as $OFFSET, or returns
29
     * $DEFAULT when it this key does not exist
30
     *
31
     * @param mixed $offset
32
     * @param mixed $default
33
     * @return mixed
34
     */
35 1
    public function offsetGet($offset, $default = null)
36
    {
37 1
        foreach ($this as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Zicht\Itertools\lib\Traits\ArrayAccessTrait> is not traversable.
Loading history...
38 1
            if ($key === $offset) {
39 1
                return $value;
40
            }
41
        }
42 1
        return $default;
43
    }
44
45
    /**
46
     * Not implemented
47
     *
48
     * @param mixed $offset
49
     * @param mixed $value
50
     */
51 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...
52
    {
53 1
        throw new \RuntimeException('It is not possible to set iterator values');
54
    }
55
56
    /**
57
     * Not implemented
58
     *
59
     * @param mixed $offset
60
     */
61 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...
62
    {
63 1
        throw new \RuntimeException('It is not possible to unset iterator values');
64
    }
65
}
66