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

ArrayWalkTransformer::__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\NodalFlow\YaEtlException;
13
use fab2s\YaEtl\Transformers\TransformerAbstract;
14
15
/**
16
 * Class ArrayWalkTransformer
17
 */
18 View Code Duplication
class ArrayWalkTransformer 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...
19
{
20
    /**
21
     * Any callable with two argument which returns something
22
     *
23
     * @var callable
24
     */
25
    protected $callable;
26
27
    /**
28
     * @var mixed
29
     */
30
    protected $userdata;
31
32
    /**
33
     * @param callable   $callable Worth nothing to say that the first callback argument should
34
     *                             be a reference if you want anything to append to the record
35
     * @param null|mixed $userdata
36
     */
37
    public function __construct(callable $callable, $userdata = null)
38
    {
39
        $this->callable = $callable;
40
        $this->userdata = $userdata;
41
    }
42
43
    /**
44
     * Execute the array_map call
45
     *
46
     * @param mixed $record
47
     *
48
     * @return mixed
49
     */
50
    public function exec($record)
51
    {
52
        if (!\array_walk($this->callable, $record, $this->userdata)) {
53
            throw new YaEtlException('array_walk call failed', 1, null, [
54
                'record' => $record,
55
            ]);
56
        }
57
58
        return $record;
59
    }
60
}
61