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

SimpleItem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 43
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 1
A transform() 0 17 3
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