GetterTrait::get()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 11
loc 11
ccs 6
cts 6
cp 1
crap 4
rs 9.9
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 GetterTrait
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 has($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 1 View Code Duplication
    public function get($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 1
        if ($this instanceof \Traversable) {
39 1
            foreach ($this as $key => $value) {
40 1
                if ($key === $offset) {
41 1
                    return $value;
42
                }
43
            }
44
        }
45 1
        return $default;
46
    }
47
}
48