Conditions | 2 |
Paths | 1 |
Total 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 |
||
14 | public function build(SchemaConfig $config) |
||
15 | { |
||
16 | $config->setQuery( |
||
17 | new ObjectType([ |
||
18 | 'name' => 'RootQueryType', |
||
19 | 'fields' => [ |
||
20 | 'latestPost' => [ |
||
21 | 'type' => new ObjectType([ |
||
22 | 'name' => 'Post', |
||
23 | 'fields' => [ |
||
24 | 'id' => [ |
||
25 | 'type' => new IntType(), |
||
26 | 'args' => [ |
||
27 | 'comment_id' => new IntType() |
||
28 | ] |
||
29 | ], |
||
30 | 'comments' => [ |
||
31 | 'type' => new ListType(new ObjectType([ |
||
32 | 'name' => 'Comment', |
||
33 | 'fields' => [ |
||
34 | 'comment_id' => new IntType() |
||
35 | ] |
||
36 | ])), |
||
37 | 'args' => [ |
||
38 | 'comment_id' => new IntType() |
||
39 | ] |
||
40 | ] |
||
41 | ] |
||
42 | ]), |
||
43 | 'resolve' => function ($source, array $args, ResolveInfo $info) { |
||
44 | $internalArgs = [ |
||
45 | 'comment_id' => 200 |
||
46 | ]; |
||
47 | if ($field = $info->getFieldAST('comments')->hasArguments()) { |
||
|
|||
48 | $internalArgs['comment_id'] = $info->getFieldAST('comments')->getArgumentValue('comment_id'); |
||
49 | } |
||
50 | |||
51 | return [ |
||
52 | "id" => 1, |
||
53 | "title" => "New approach in API has been revealed", |
||
54 | "summary" => "In two words - GraphQL Rocks!", |
||
55 | "comments" => [ |
||
56 | [ |
||
57 | "comment_id" => $internalArgs['comment_id'] |
||
58 | ] |
||
59 | ] |
||
60 | ]; |
||
61 | }, |
||
62 | 'args' => [ |
||
63 | 'id' => new IntType() |
||
64 | ] |
||
65 | ] |
||
66 | ] |
||
67 | ]) |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.