Completed
Push — master ( ac0544...a10425 )
by Nate
11:46 queued 42s
created

SimpleItem::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
crap 2
1
<?php
2
3
/**
4
 * @author    Flipbox Factory
5
 * @copyright Copyright (c) 2017, Flipbox Digital
6
 * @link      https://github.com/flipbox/transform/releases/latest
7
 * @license   https://github.com/flipbox/transform/blob/master/LICENSE
8
 */
9
10
namespace Flipbox\Transform\Resources;
11
12
use Flipbox\Transform\Traits\ExtraParameterTrait;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 3.0.0
17
 */
18
class SimpleItem implements ResourceInterface
19
{
20
    use ExtraParameterTrait;
21
22
    /**
23
     * @param $data
24
     * @param callable $transformer
25
     * @param array $extra
26
     * @return array|null
27
     */
28
    public function __invoke($data, callable $transformer, array $extra = [])
29
    {
30
        return $this->transform(
31
            $transformer,
32
            $data,
33
            $extra
34
        );
35
    }
36
37
    /**
38
     * @param callable $transformer
39
     * @param $data
40
     * @param array $extra
41
     * @return mixed
42
     */
43
    public function transform(callable $transformer, $data, array $extra = [])
44
    {
45
        $args = [$data, null];
46
47
        if (!empty($extra)) {
48
            try {
49
                $args = array_merge(
50
                    $args,
51
                    $this->validParams($transformer, $extra)
52
                );
53
            } catch (\ReflectionException $e) {
54
                // Sorry
55
            }
56
        }
57
58
        return call_user_func_array($transformer, $args);
59
    }
60
}
61