ArrayReplaceRecursiveTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exec() 0 3 1
A __construct() 0 5 1
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\NodalFlow\NodalFlowException;
13
use fab2s\YaEtl\Transformers\TransformerAbstract;
14
15
/**
16
 * Class ArrayReplaceRecursiveTransformer
17
 */
18
class ArrayReplaceRecursiveTransformer extends TransformerAbstract
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $default;
24
25
    /**
26
     * @var array
27
     */
28
    protected $override;
29
30
    /**
31
     * @param array $default  An array of the default field values to use, if any
32
     * @param array $override An array of the field to always set to the same value, if any
33
     *
34
     * @throws NodalFlowException
35
     */
36
    public function __construct(array $default, array $override = [])
37
    {
38
        $this->default  = $default;
39
        $this->override = $override;
40
        parent::__construct();
41
    }
42
43
    /**
44
     * Set defaults and/or overrides recursively in the record
45
     *
46
     * @param array $record
47
     *
48
     * @return array
49
     */
50
    public function exec($record = null)
51
    {
52
        return \array_replace_recursive($this->default, $record, $this->override);
0 ignored issues
show
Bug introduced by
It seems like $record can also be of type null; however, parameter $replacements of array_replace_recursive() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        return \array_replace_recursive($this->default, /** @scrutinizer ignore-type */ $record, $this->override);
Loading history...
53
    }
54
}
55