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

ValueIndexer::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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