RecordMapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 24
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace mindplay\sql\framework\mappers;
4
5
use mindplay\sql\framework\Mapper;
6
use Traversable;
7
8
/**
9
 * Use this Mapper for quick, on-demand record mapping - as an alternative to implementing an actual Mapper class.
10
 */
11
class RecordMapper implements Mapper
12
{
13
    /**
14
     * @var callable(array<string,mixed>):array<string,mixed>
15
     */
16
    private $mapper;
17
18
    /**
19
     * @param callable(array<string,mixed>):array<string,mixed> $mapper function (array $record_set): array
20
     */
21 1
    public function __construct(callable $mapper)
22
    {
23 1
        $this->mapper = $mapper;
24
    }
25
26 1
    public function map(array $record_set): array|Traversable
27
    {
28 1
        $result = [];
29
30 1
        foreach ($record_set as $key => $record) {
31 1
            $result[$key] = call_user_func($this->mapper, $record);
32
        }
33
34 1
        return $result;
35
    }
36
}
37