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

ValueIndexer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 8 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