Completed
Pull Request — master (#34)
by Rasmus
05:13
created

ValueIndexer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace mindplay\sql\framework\indexers;
4
5
use mindplay\sql\framework\Indexer;
6
use UnexpectedValueException;
7
8
/**
9
 * This indexer takes a specific named value from a given record
10
 */
11
class ValueIndexer implements Indexer
12
{
13
    /**
14
     * @var string
15
     */
16
    private $name;
17
18
    /**
19
     * @param string $name
20
     */
21 1
    public function __construct($name)
22
    {
23 1
        $this->name = $name;
24 1
    }
25
26 1
    public function index(array $record)
27
    {
28 1
        if (!isset($record[$this->name])) {
29 1
            throw new UnexpectedValueException("the given record does not contain a value named: {$this->name}");
30
        }
31
32 1
        return $record[$this->name];
33
    }
34
}
35