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

AbstractSimpleTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 39
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
__invoke() 0 1 ?
A __construct() 0 4 1
A item() 0 4 1
A collection() 0 4 1
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\Transformers;
11
12
use Flipbox\Transform\Helpers\ObjectHelper;
13
use Flipbox\Transform\Resources\SimpleCollection;
14
use Flipbox\Transform\Resources\SimpleItem;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 3.0.0
19
 */
20
abstract class AbstractSimpleTransformer
21
{
22
    /**
23
     * @param $data
24
     * @param string $identifier
25
     * @return mixed
26
     */
27
    abstract public function __invoke($data, string $identifier = null);
28
29
    /**
30
     * @param array $config
31
     */
32
    public function __construct(array $config = [])
33
    {
34
        ObjectHelper::configure($this, $config);
35
    }
36
37
    /**
38
     * @param mixed $data
39
     * @param callable $transformer
40
     * @param array $extra
41
     * @return mixed
42
     */
43
    protected function item($data, callable $transformer, array $extra = [])
44
    {
45
        return call_user_func_array(new SimpleItem(), [$data, $transformer, $extra]);
46
    }
47
48
    /**
49
     * @param mixed $data
50
     * @param callable $transformer
51
     * @param array $extra
52
     * @return mixed
53
     */
54
    protected function collection($data, $transformer, array $extra = [])
55
    {
56
        return call_user_func_array(new SimpleCollection(), [$data, $transformer, $extra]);
57
    }
58
}
59