We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 9 |
Paths | 256 |
Total Lines | 61 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Tests | 41 |
CRAP Score | 9 |
Changes | 1 | ||
Bugs | 1 | Features | 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 |
||
18 | 3 | public function toMappingDefinition(array $config) |
|
19 | { |
||
20 | 3 | $name = $config['name']; |
|
21 | 3 | $namePrefix = preg_replace('/(.*)?Connection$/', '$1', $name); |
|
22 | |||
23 | //Edge |
||
24 | 3 | $edgeName = $namePrefix.'Edge'; |
|
25 | 3 | $edgeFields = empty($config['edgeFields']) || !is_array($config['edgeFields']) ? [] : $config['edgeFields']; |
|
26 | 3 | $nodeType = empty($config['nodeType']) || !is_string($config['nodeType']) ? null : $config['nodeType']; |
|
27 | 3 | $resolveNode = empty($config['resolveNode']) ? null : $config['resolveNode']; |
|
28 | 3 | $resolveCursor = empty($config['resolveCursor']) ? null : $config['resolveNode']; |
|
29 | |||
30 | //connection |
||
31 | 3 | $connectionName = $namePrefix.'Connection'; |
|
32 | 3 | $connectionFields = empty($config['connectionFields']) || !is_array($config['connectionFields']) ? [] : $config['connectionFields']; |
|
33 | |||
34 | return [ |
||
35 | $edgeName => [ |
||
36 | 3 | 'type' => 'object', |
|
37 | 'config' => [ |
||
38 | 3 | 'name' => $edgeName, |
|
39 | 3 | 'description' => 'An edge in a connection.', |
|
40 | 3 | 'fields' => array_merge( |
|
41 | 3 | $edgeFields, |
|
42 | [ |
||
43 | 'node' => [ |
||
44 | 3 | 'type' => $nodeType, |
|
45 | 3 | 'resolve' => $resolveNode, |
|
46 | 3 | 'description' => 'The item at the end of the edge.', |
|
47 | 3 | ], |
|
48 | 'cursor' => [ |
||
49 | 3 | 'type' => 'String!', |
|
50 | 3 | 'resolve' => $resolveCursor, |
|
51 | 3 | 'description' => 'A cursor for use in pagination.', |
|
52 | 3 | ], |
|
53 | ] |
||
54 | 3 | ), |
|
55 | 3 | ], |
|
56 | 3 | ], |
|
57 | $connectionName => [ |
||
58 | 3 | 'type' => 'object', |
|
59 | 'config' => [ |
||
60 | 3 | 'name' => $connectionName, |
|
61 | 3 | 'description' => 'A connection to a list of items.', |
|
62 | 3 | 'fields' => array_merge( |
|
63 | 3 | $connectionFields, |
|
64 | [ |
||
65 | 'pageInfo' => [ |
||
66 | 3 | 'type' => 'PageInfo!', |
|
67 | 3 | 'description' => 'Information to aid in pagination.', |
|
68 | 3 | ], |
|
69 | 'edges' => [ |
||
70 | 3 | 'type' => "[$edgeName]", |
|
71 | 3 | 'description' => 'Information to aid in pagination.', |
|
72 | 3 | ], |
|
73 | ] |
||
74 | 3 | ), |
|
75 | 3 | ], |
|
76 | 3 | ], |
|
77 | 3 | ]; |
|
78 | } |
||
79 | } |
||
80 |