Passed
Push — master ( 0057b2...3e8fcf )
by Marek
02:11
created

BitbucketMapperFactory::create()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 81
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 8.8076
c 0
b 0
f 0
cc 1
eloc 43
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace AppBuilder\Application\Utils\Mapper\Factory;
6
7
use AppBuilder\Application\Utils\Mapper\ArrayMapper;
8
use AppBuilder\Application\Utils\Mapper\FieldMapper;
9
use Closure;
10
11
class BitbucketMapperFactory
12
{
13
    /**
14
     * Returns a structure of mappers depending on expected result structure.
15
     */
16
    public static function create() : array
17
    {
18
        /** @var Closure */
19
        $stringClosure = function (string $data) : string {
20
            return $data;
21
        };
22
23
        return [
24
            /* Name */
25
            new ArrayMapper('detail', [
26
                new ArrayMapper('0', [
27
                    new ArrayMapper('pullRequests', [
28
                        new ArrayMapper('0', [
29
                            new FieldMapper('name', $stringClosure),
30
                        ]),
31
                    ]),
32
                ]),
33
            ], 'pull_request_name'),
34
35
            /* Url */
36
            new ArrayMapper('detail', [
37
                new ArrayMapper('0', [
38
                    new ArrayMapper('pullRequests', [
39
                        new ArrayMapper('0', [
40
                            new FieldMapper('url', $stringClosure),
41
                        ]),
42
                    ]),
43
                ]),
44
            ], 'pull_request_url'),
45
46
            /* Status */
47
            new ArrayMapper('detail', [
48
                new ArrayMapper('0', [
49
                    new ArrayMapper('pullRequests', [
50
                        new ArrayMapper('0', [
51
                            new FieldMapper('status', $stringClosure),
52
                        ]),
53
                    ]),
54
                ]),
55
            ], 'pull_request_status'),
56
57
            /* Last update */
58
            new ArrayMapper('detail', [
59
                new ArrayMapper('0', [
60
                    new ArrayMapper('pullRequests', [
61
                        new ArrayMapper('0', [
62
                            new FieldMapper('lastUpdate', $stringClosure),
63
                        ]),
64
                    ]),
65
                ]),
66
            ], 'pull_request_last_update'),
67
68
            /* Branch */
69
            new ArrayMapper('detail', [
70
                new ArrayMapper('0', [
71
                    new ArrayMapper('pullRequests', [
72
                        new ArrayMapper('0', [
73
                            new ArrayMapper('source', [
74
                                new FieldMapper('branch', $stringClosure),
75
                            ]),
76
                        ]),
77
                    ]),
78
                ]),
79
            ], 'pull_request_branch'),
80
81
            /* Repository */
82
            new ArrayMapper('detail', [
83
                new ArrayMapper('0', [
84
                    new ArrayMapper('pullRequests', [
85
                        new ArrayMapper('0', [
86
                            new ArrayMapper('source', [
87
                                new ArrayMapper('repository', [
88
                                    new FieldMapper('name', $stringClosure),
89
                                ]),
90
                            ]),
91
                        ]),
92
                    ]),
93
                ]),
94
            ], 'repository'),
95
        ];
96
    }
97
}
98