Completed
Push — master ( dbd271...8b4cd1 )
by Mārtiņš
02:56
created

DataMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 9
loc 39
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A applyValues() 9 9 3

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 Palladium\Component;
4
5
use PDO;
6
7
abstract class DataMapper
8
{
9
10
    protected $connection;
11
    protected $table;
12
13
14
    /**
15
     * Creates new mapper instance
16
     *
17
     * @param PDO $connection
18
     * @param string $table A list of table name aliases
19
     *
20
     * @codeCoverageIgnore
21
     */
22
    public function __construct(PDO $connection, string $table)
23
    {
24
        $this->connection = $connection;
25
        $this->table = $table;
26
    }
27
28
29
    /**
30
     * Method for populating the doven instance with values from the array via setters
31
     *
32
     * @param object $instance The object to be populated with values
33
     * @param array $parameters A key-value array, that will be matched to setters
34
     */
35 1 View Code Duplication
    public function applyValues($instance, array $parameters)
0 ignored issues
show
Duplication introduced by
This method 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...
36
    {
37 1
        foreach ((array) $parameters as $key => $value) {
38 1
            $method = 'set' . str_replace('_', '', $key);
39 1
            if (method_exists($instance, $method)) {
40 1
                $instance->{$method}($value);
41
            }
42
        }
43 1
    }
44
45
}
46