Factory   A
last analyzed

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A collection() 0 8 2
A item() 0 10 1
A transform() 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;
11
12
/**
13
 * @author Flipbox Factory <[email protected]>
14
 * @since 3.0.0
15
 */
16
class Factory
17
{
18
    /**
19
     * @param callable $transformer
20
     * @param $data
21
     * @param array $extra
22
     * @return array|null
23
     */
24
    public static function collection(callable $transformer, $data, array $extra = []): array
25
    {
26
        $items = [];
27
        foreach ($data as $item) {
28
            $items[] = self::item($transformer, $item, $extra);
29
        }
30
        return $items;
31
    }
32
33
    /**
34
     * @param callable $transformer
35
     * @param $data
36
     * @param array $extra
37
     * @return mixed
38
     */
39
    public static function item(callable $transformer, $data, array $extra = [])
40
    {
41
        return call_user_func_array(
42
            $transformer,
43
            array_merge(
44
                [$data],
45
                $extra
46
            )
47
        );
48
    }
49
50
    /**
51
     * @param array $config
52
     * @return Transform
53
     */
54
    public static function transform(array $config = []): Transform
55
    {
56
        return new Transform($config);
57
    }
58
}
59