GetterTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 55 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 22
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 11 11 4
A get() 11 11 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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