CallableTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 0
dl 0
loc 39
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromCallable() 0 4 1
A setTransformer() 0 6 1
A transform() 0 4 1
1
<?php
2
namespace Madewithlove\Export\Csv\Transformers;
3
4
use Madewithlove\Export\Csv\Transformer;
5
6
class CallableTransformer implements Transformer
7
{
8
    /**
9
     * @var callable
10
     */
11
    private $wrapped;
12
13
    /**
14
     * @param callable $transformer
15
     *
16
     * @return static
17
     */
18 2
    public static function fromCallable(callable $transformer)
19
    {
20 2
        return (new static())->setTransformer($transformer);
21
    }
22
23
    /**
24
     * @param callable $wrapped
25
     *
26
     * @return static
27
     */
28 5
    public function setTransformer(callable $wrapped)
29
    {
30 5
        $this->wrapped = $wrapped;
31
32 5
        return $this;
33
    }
34
35
    /**
36
     * @param array $row
37
     *
38
     * @return array
39
     */
40 4
    public function transform(array $row)
41
    {
42 4
        return call_user_func($this->wrapped, $row);
43
    }
44
}
45