GetFirstOperation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 23
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 5 2
1
<?php
2
/**
3
 * File was created 08.05.2015 15:26
4
 *
5
 * @author Karsten J. Gerber <[email protected]>
6
 */
7
8
namespace PeekAndPoke\Component\Psi\Operation\Terminal;
9
10
use PeekAndPoke\Component\Psi\TerminalOperation;
11
12
/**
13
 * GetFirstOperation
14
 *
15
 * @author Karsten J. Gerber <[email protected]>
16
 */
17
class GetFirstOperation implements TerminalOperation
18
{
19
    /** @var */
20
    private $default;
21
22
    /**
23
     * @param mixed $default
24
     */
25 17
    public function __construct($default)
26
    {
27 17
        $this->default = $default;
28 17
    }
29
30
    /**
31
     * @param \Iterator $set
32
     *
33
     * @return mixed
34
     */
35 17
    public function apply(\Iterator $set)
36
    {
37 17
        $set->rewind();
38
39 17
        return $set->valid() ? $set->current() : $this->default;
40
    }
41
}
42