| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 46 |
| 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 |
||
| 27 | public function register() |
||
| 28 | { |
||
| 29 | $this->container->add(GraphQL::INCLUDE_DIRECTIVE, function () { |
||
| 30 | return GraphQLDirective([ |
||
| 31 | 'name' => 'include', |
||
| 32 | 'description' => |
||
| 33 | 'Directs the executor to include this field or fragment only when ' . |
||
| 34 | 'the `if` argument is true.', |
||
| 35 | 'locations' => [ |
||
| 36 | DirectiveLocationEnum::FIELD, |
||
| 37 | DirectiveLocationEnum::FRAGMENT_SPREAD, |
||
| 38 | DirectiveLocationEnum::INLINE_FRAGMENT, |
||
| 39 | ], |
||
| 40 | 'args' => [ |
||
| 41 | 'if' => [ |
||
| 42 | 'type' => GraphQLNonNull(GraphQLBoolean()), |
||
| 43 | 'description' => 'Included when true.', |
||
| 44 | ], |
||
| 45 | ], |
||
| 46 | ]); |
||
| 47 | }, true/* $shared */); |
||
| 48 | |||
| 49 | $this->container->add(GraphQL::SKIP_DIRECTIVE, function () { |
||
| 50 | return GraphQLDirective([ |
||
| 51 | 'name' => 'skip', |
||
| 52 | 'description' => |
||
| 53 | 'Directs the executor to skip this field or fragment when the `if` ' . |
||
| 54 | 'argument is true.', |
||
| 55 | 'locations' => [ |
||
| 56 | DirectiveLocationEnum::FIELD, |
||
| 57 | DirectiveLocationEnum::FRAGMENT_SPREAD, |
||
| 58 | DirectiveLocationEnum::INLINE_FRAGMENT, |
||
| 59 | ], |
||
| 60 | 'args' => [ |
||
| 61 | 'if' => [ |
||
| 62 | 'type' => GraphQLNonNull(GraphQLBoolean()), |
||
| 63 | 'description' => 'Skipped when true.', |
||
| 64 | ], |
||
| 65 | ], |
||
| 66 | ]); |
||
| 67 | }, true/* $shared */); |
||
| 68 | |||
| 69 | $this->container->add(GraphQL::DEPRECATED_DIRECTIVE, function () { |
||
| 70 | return GraphQLDirective([ |
||
| 71 | 'name' => 'deprecated', |
||
| 72 | 'description' => 'Marks an element of a GraphQL schema as no longer supported.', |
||
| 73 | 'locations' => [ |
||
| 74 | DirectiveLocationEnum::FIELD_DEFINITION, |
||
| 75 | DirectiveLocationEnum::ENUM_VALUE, |
||
| 76 | ], |
||
| 77 | 'args' => [ |
||
| 78 | 'reason' => [ |
||
| 79 | 'type' => GraphQLString(), |
||
| 80 | 'description' => |
||
| 81 | 'Explains why this element was deprecated, usually also including a ' . |
||
| 82 | 'suggestion for how to access supported similar data. Formatted ' . |
||
| 83 | 'in [Markdown](https://daringfireball.net/projects/markdown/).', |
||
| 84 | 'defaultValue' => DEFAULT_DEPRECATION_REASON, |
||
| 85 | ], |
||
| 86 | ] |
||
| 87 | ]); |
||
| 88 | }, true/* $shared */); |
||
| 89 | } |
||
| 91 |