Completed
Push — master ( 6ea5e4...20d81d )
by Rasmus
04:22
created

RecordMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 0
dl 26
loc 26
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A map() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace mindplay\sql\framework;
4
5
/**
6
 * Use this Mapper for quick, on-demand record mapping - as an alternative to implementing an actual Mapper class.
7
 */
8 View Code Duplication
class RecordMapper implements Mapper
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * @var callable
12
     */
13
    private $mapper;
14
15
    /**
16
     * @param callable $mapper function (array $record_set) : array
17
     */
18
    public function __construct(callable $mapper)
19
    {
20
        $this->mapper = $mapper;
21
    }
22
23
    public function map(array $record_set)
24
    {
25
        $result = [];
26
27
        foreach ($record_set as $key => $record) {
28
            $result[$key] = call_user_func($this->mapper, $record);
29
        }
30
31
        return $result;
32
    }
33
}
34