LastTrait::last()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 11
loc 11
ccs 6
cts 6
cp 1
crap 3
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 View Code Duplication
trait LastTrait
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 last 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 last($default = null)
18
    {
19 7
        if ($this instanceof \Iterator) {
20 6
            $item = $default;
21 6
            foreach ($this as $item) {
22
            }
23 6
            return $item;
24
        }
25
26 1
        return null;
27
    }
28
29
    /**
30
     * Returns the key of the last element of this iterable or
31
     * returns $DEFAULT when this iterable is empty
32
     *
33
     * @param mixed $default
34
     * @return mixed
35
     */
36 7
    public function lastKey($default = null)
37
    {
38 7
        if ($this instanceof \Iterator) {
39 6
            $key = $default;
40 6
            foreach ($this as $key => $value) {
41
            }
42 6
            return $key;
43
        }
44
45 1
        return null;
46
    }
47
}
48