ArrayWalkRecursiveTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A exec() 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 ArrayWalkRecursiveTransformer
17
 */
18
class ArrayWalkRecursiveTransformer extends TransformerAbstract
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
     * @throws NodalFlowException
38
     */
39
    public function __construct(callable $callable, $userData = null)
40
    {
41
        $this->callable = $callable;
42
        $this->userData = $userData;
43
        parent::__construct();
44
    }
45
46
    /**
47
     * Execute the array_map call
48
     *
49
     * @param array $record
50
     *
51
     * @return array
52
     */
53
    public function exec($record = null)
54
    {
55
        \array_walk_recursive($record, $this->callable, $this->userData);
0 ignored issues
show
Bug introduced by
It seems like $record can also be of type null; however, parameter $array of array_walk_recursive() does only seem to accept array|object, 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

55
        \array_walk_recursive(/** @scrutinizer ignore-type */ $record, $this->callable, $this->userData);
Loading history...
56
57
        return $record;
58
    }
59
}
60