Passed
Push — master ( 7bba5d...c1c3fd )
by Fabrice
02:35
created

ArrayReplaceTransformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 1
dl 34
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A exec() 4 4 1

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
/*
4
 * This file is part of YaEtl.
5
 *     (c) Fabrice de Stefanis / https://github.com/fab2s/YaEtl
6
 * This source file is licensed under the MIT license which you will
7
 * find in the LICENSE file or at https://opensource.org/licenses/MIT
8
 */
9
10
namespace fab2s\YaEtl\Transformers\Arrays;
11
12
use fab2s\YaEtl\Transformers\TransformerAbstract;
13
14
/**
15
 * Class ArrayReplaceTransformer
16
 */
17 View Code Duplication
class ArrayReplaceTransformer extends TransformerAbstract
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...
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $default;
23
24
    /**
25
     * @var array
26
     */
27
    protected $override;
28
29
    /**
30
     * @param array $default  An array of the default field values to use, if any
31
     * @param array $override An array of the field to always set to the same value, if any
32
     */
33
    public function __construct(array $default, array $override = [])
34
    {
35
        $this->default  = $default;
36
        $this->override = $override;
37
    }
38
39
    /**
40
     * Set defaults and/or overrides in the record
41
     *
42
     * @param mixed $record
43
     *
44
     * @return mixed
45
     */
46
    public function exec($record)
47
    {
48
        return \array_replace($this->default, $record, $this->override);
49
    }
50
}
51