CallableTransformer::fromCallable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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