FirstTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 42
loc 42
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A first() 12 12 3
A firstKey() 12 12 3

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 View Code Duplication
trait FirstTrait
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * Returns the first element of this iterable or
12
     * returns $default when this iterable is empty
13
     *
14
     * @param mixed $default
15
     * @return mixed
16
     */
17 7
    public function first($default = null)
18
    {
19 7
        if ($this instanceof \Iterator) {
20 6
            $item = $default;
21 6
            foreach ($this as $item) {
22 3
                break;
23
            }
24 6
            return $item;
25
        }
26
27 1
        return null;
28
    }
29
30
    /**
31
     * Returns the key of the first element of this iterable or
32
     * returns $DEFAULT when this iterable is empty
33
     *
34
     * @param mixed $default
35
     * @return mixed
36
     */
37 7
    public function firstKey($default = null)
38
    {
39 7
        if ($this instanceof \Iterator) {
40 6
            $key = $default;
41 6
            foreach ($this as $key => $value) {
42 3
                break;
43
            }
44 6
            return $key;
45
        }
46
47 1
        return null;
48
    }
49
}
50