Conditions | 1 |
Paths | 1 |
Total Lines | 103 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | public static function create() : array |
||
17 | { |
||
18 | /** @var Closure */ |
||
19 | $intClosure = function (string $data) : int { |
||
20 | return (int) $data; |
||
21 | }; |
||
22 | |||
23 | /** @var Closure */ |
||
24 | $stringClosure = function (string $data) : string { |
||
25 | return $data; |
||
26 | }; |
||
27 | |||
28 | /** @var Closure */ |
||
29 | $boolClosure = function (?bool $data) : bool { |
||
30 | return $data; |
||
31 | }; |
||
32 | |||
33 | return [ |
||
34 | new FieldMapper('id', $intClosure), |
||
35 | new FieldMapper('key', $stringClosure, 'ticket_key'), |
||
36 | |||
37 | /* Assignee name */ |
||
38 | new ArrayMapper('fields', [ |
||
39 | new ArrayMapper('assignee', [ |
||
40 | new FieldMapper('name', $stringClosure), |
||
41 | ]), |
||
42 | ], 'assignee_name'), |
||
43 | |||
44 | /* Assignee email */ |
||
45 | new ArrayMapper('fields', [ |
||
46 | new ArrayMapper('assignee', [ |
||
47 | new FieldMapper('emailAddress', $stringClosure, 'email'), |
||
48 | ]), |
||
49 | ], 'assignee_email'), |
||
50 | |||
51 | /* Assignee display name */ |
||
52 | new ArrayMapper('fields', [ |
||
53 | new ArrayMapper('assignee', [ |
||
54 | new FieldMapper('displayName', $stringClosure, 'display_name'), |
||
55 | ]), |
||
56 | ], 'assignee_display_name'), |
||
57 | |||
58 | /* Assignee active */ |
||
59 | new ArrayMapper('fields', [ |
||
60 | new ArrayMapper('assignee', [ |
||
61 | new FieldMapper('active', $boolClosure), |
||
62 | ]), |
||
63 | ], 'assignee_active'), |
||
64 | |||
65 | /* Status */ |
||
66 | new ArrayMapper('fields', [ |
||
67 | new ArrayMapper('status', [ |
||
68 | new FieldMapper('name', $stringClosure, 'status'), |
||
69 | ]), |
||
70 | ], 'status'), |
||
71 | |||
72 | /* Status category */ |
||
73 | new ArrayMapper('fields', [ |
||
74 | new ArrayMapper('status', [ |
||
75 | new ArrayMapper('statuscategory', [ |
||
76 | new FieldMapper('name', $stringClosure, 'status_category'), |
||
77 | ]), |
||
78 | ]), |
||
79 | ], 'status_category'), |
||
80 | |||
81 | /* Components */ |
||
82 | new ArrayMapper('fields', [ |
||
83 | new ArrayMapper('components', [ |
||
84 | new ArrayMapper('0', [ |
||
85 | new FieldMapper('name', $stringClosure), |
||
86 | ]), |
||
87 | ]), |
||
88 | ], 'components'), |
||
89 | |||
90 | /* Issue type */ |
||
91 | new ArrayMapper('fields', [ |
||
92 | new ArrayMapper('issuetype', [ |
||
93 | new FieldMapper('name', $stringClosure, 'ticket_type'), |
||
94 | ]), |
||
95 | ], 'ticket_type'), |
||
96 | |||
97 | /* Project */ |
||
98 | new ArrayMapper('fields', [ |
||
99 | new ArrayMapper('project', [ |
||
100 | new FieldMapper('name', $stringClosure, 'project'), |
||
101 | ]), |
||
102 | ], 'project'), |
||
103 | |||
104 | /* Fix version */ |
||
105 | new ArrayMapper('fields', [ |
||
106 | new ArrayMapper('fixVersions', [ |
||
107 | new ArrayMapper('0', [ |
||
108 | new FieldMapper('name', $stringClosure, 'fix_version'), |
||
109 | ]), |
||
110 | ]), |
||
111 | ], 'fix_version'), |
||
112 | |||
113 | /* Summary */ |
||
114 | new ArrayMapper('fields', [ |
||
115 | new FieldMapper('summary', $stringClosure), |
||
116 | ], 'summary'), |
||
117 | ]; |
||
118 | } |
||
119 | } |
||
120 |