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

ArrayReplaceTransformer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 5
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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