Conditions | 1 |
Paths | 1 |
Total Lines | 79 |
Code Lines | 51 |
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 |
||
14 | protected function buildSchema() |
||
15 | { |
||
16 | $schema = new Schema([ |
||
17 | 'query' => new ObjectType([ |
||
18 | 'name' => 'Query', |
||
19 | 'fields' => [ |
||
20 | 'f1' => [ |
||
21 | 'type' => Type::string(), |
||
22 | 'resolve' => function($root, $args, $context, $info) { |
||
23 | return $info->fieldName; |
||
24 | } |
||
25 | ], |
||
26 | 'fieldWithPhpError' => [ |
||
27 | 'type' => Type::string(), |
||
28 | 'resolve' => function($root, $args, $context, $info) { |
||
29 | trigger_error('deprecated', E_USER_DEPRECATED); |
||
30 | trigger_error('notice', E_USER_NOTICE); |
||
31 | trigger_error('warning', E_USER_WARNING); |
||
32 | $a = []; |
||
33 | $a['test']; // should produce PHP notice |
||
34 | return $info->fieldName; |
||
35 | } |
||
36 | ], |
||
37 | 'fieldWithException' => [ |
||
38 | 'type' => Type::string(), |
||
39 | 'resolve' => function($root, $args, $context, $info) { |
||
40 | throw new UserError("This is the exception we want"); |
||
41 | } |
||
42 | ], |
||
43 | 'testContextAndRootValue' => [ |
||
44 | 'type' => Type::string(), |
||
45 | 'resolve' => function($root, $args, $context, $info) { |
||
46 | $context->testedRootValue = $root; |
||
47 | return $info->fieldName; |
||
48 | } |
||
49 | ], |
||
50 | 'fieldWithArg' => [ |
||
51 | 'type' => Type::string(), |
||
52 | 'args' => [ |
||
53 | 'arg' => [ |
||
54 | 'type' => Type::nonNull(Type::string()) |
||
55 | ], |
||
56 | ], |
||
57 | 'resolve' => function($root, $args) { |
||
58 | return $args['arg']; |
||
59 | } |
||
60 | ], |
||
61 | 'dfd' => [ |
||
62 | 'type' => Type::string(), |
||
63 | 'args' => [ |
||
64 | 'num' => [ |
||
65 | 'type' => Type::nonNull(Type::int()) |
||
66 | ], |
||
67 | ], |
||
68 | 'resolve' => function($root, $args, $context) { |
||
69 | $context['buffer']($args['num']); |
||
70 | |||
71 | return new Deferred(function() use ($args, $context) { |
||
72 | return $context['load']($args['num']); |
||
73 | }); |
||
74 | } |
||
75 | ] |
||
76 | ] |
||
77 | ]), |
||
78 | 'mutation' => new ObjectType([ |
||
79 | 'name' => 'Mutation', |
||
80 | 'fields' => [ |
||
81 | 'm1' => [ |
||
82 | 'type' => new ObjectType([ |
||
83 | 'name' => 'TestMutation', |
||
84 | 'fields' => [ |
||
85 | 'result' => Type::string() |
||
86 | ] |
||
87 | ]) |
||
88 | ] |
||
89 | ] |
||
90 | ]) |
||
91 | ]); |
||
92 | return $schema; |
||
93 | } |
||
95 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.