GetFirstOperation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 1
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