| Conditions | 11 |
| Paths | 1 |
| Total Lines | 113 |
| Code Lines | 80 |
| 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 |
||
| 34 | public function register() |
||
| 35 | { |
||
| 36 | $this->container->add(GraphQL::BOOLEAN, function () { |
||
| 37 | return GraphQLScalarType([ |
||
| 38 | 'name' => TypeNameEnum::BOOLEAN, |
||
| 39 | 'description' => 'The `Boolean` scalar type represents `true` or `false`.', |
||
| 40 | 'serialize' => function ($value) { |
||
| 41 | return coerceBoolean($value); |
||
| 42 | }, |
||
| 43 | 'parseValue' => function ($value) { |
||
| 44 | return coerceBoolean($value); |
||
| 45 | }, |
||
| 46 | |||
| 47 | 'parseLiteral' => function (NodeInterface $node) { |
||
| 48 | if ($node instanceof BooleanValueNode) { |
||
| 49 | return $node->getValue(); |
||
| 50 | } |
||
| 51 | return null; |
||
| 52 | }, |
||
| 53 | ]); |
||
| 54 | }, true/* $shared */); |
||
| 55 | |||
| 56 | $this->container->add(GraphQL::FLOAT, function () { |
||
| 57 | return GraphQLScalarType([ |
||
| 58 | 'name' => TypeNameEnum::FLOAT, |
||
| 59 | 'description' => |
||
| 60 | 'The `Float` scalar type represents signed double-precision fractional ' . |
||
| 61 | 'values as specified by ' . |
||
| 62 | '[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).', |
||
| 63 | 'serialize' => function ($value) { |
||
| 64 | return coerceFloat($value); |
||
| 65 | }, |
||
| 66 | 'parseValue' => function ($value) { |
||
| 67 | return coerceFloat($value); |
||
| 68 | }, |
||
| 69 | 'parseLiteral' => function (NodeInterface $node) { |
||
| 70 | if ($node instanceof FloatValueNode || $node instanceof IntValueNode) { |
||
| 71 | return $node->getValue(); |
||
| 72 | } |
||
| 73 | return null; |
||
| 74 | }, |
||
| 75 | ]); |
||
| 76 | }, true/* $shared */); |
||
| 77 | |||
| 78 | $this->container->add(GraphQL::INT, function () { |
||
| 79 | return GraphQLScalarType([ |
||
| 80 | 'name' => TypeNameEnum::INT, |
||
| 81 | 'description' => |
||
| 82 | 'The `Int` scalar type represents non-fractional signed whole numeric ' . |
||
| 83 | 'values. Int can represent values between -(2^31) and 2^31 - 1.', |
||
| 84 | 'serialize' => function ($value) { |
||
| 85 | return coerceInt($value); |
||
| 86 | }, |
||
| 87 | 'parseValue' => function ($value) { |
||
| 88 | return coerceInt($value); |
||
| 89 | }, |
||
| 90 | 'parseLiteral' => function (NodeInterface $node) { |
||
| 91 | if ($node instanceof IntValueNode) { |
||
| 92 | $value = (int)$node->getValue(); |
||
| 93 | if ($node->getValue() === (string)$value && $value <= PHP_INT_MAX && $value >= PHP_INT_MIN) { |
||
| 94 | return $value; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | return null; |
||
| 98 | }, |
||
| 99 | ]); |
||
| 100 | }, true/* $shared */); |
||
| 101 | |||
| 102 | $this->container->add(GraphQL::ID, function () { |
||
| 103 | return GraphQLScalarType([ |
||
| 104 | 'name' => TypeNameEnum::ID, |
||
| 105 | 'description' => |
||
| 106 | 'The `ID` scalar type represents a unique identifier, often used to ' . |
||
| 107 | 'refetch an object or as key for a cache. The ID type appears in a JSON ' . |
||
| 108 | 'response as a String; however, it is not intended to be human-readable. ' . |
||
| 109 | 'When expected as an input type, any string (such as `"4"`) or integer ' . |
||
| 110 | '(such as `4`) input value will be accepted as an ID.', |
||
| 111 | 'serialize' => function ($value) { |
||
| 112 | return coerceString($value); |
||
| 113 | }, |
||
| 114 | 'parseValue' => function ($value) { |
||
| 115 | return coerceString($value); |
||
| 116 | }, |
||
| 117 | 'parseLiteral' => function (NodeInterface $node) { |
||
| 118 | if ($node instanceof StringValueNode || $node instanceof IntValueNode) { |
||
| 119 | return $node->getValue(); |
||
| 120 | } |
||
| 121 | return null; |
||
| 122 | }, |
||
| 123 | ]); |
||
| 124 | }, true/* $shared */); |
||
| 125 | |||
| 126 | $this->container->add(GraphQL::STRING, function () { |
||
| 127 | return GraphQLScalarType([ |
||
| 128 | 'name' => TypeNameEnum::STRING, |
||
| 129 | 'description' => |
||
| 130 | 'The `String` scalar type represents textual data, represented as UTF-8 ' . |
||
| 131 | 'character sequences. The String type is most often used by GraphQL to ' . |
||
| 132 | 'represent free-form human-readable text.', |
||
| 133 | 'serialize' => function ($value) { |
||
| 134 | return coerceString($value); |
||
| 135 | }, |
||
| 136 | 'parseValue' => function ($value) { |
||
| 137 | return coerceString($value); |
||
| 138 | }, |
||
| 139 | 'parseLiteral' => function (NodeInterface $node) { |
||
| 140 | if ($node instanceof StringValueNode) { |
||
| 141 | return $node->getValue(); |
||
| 142 | } |
||
| 143 | return null; |
||
| 144 | }, |
||
| 145 | ]); |
||
| 146 | }, true/* $shared */); |
||
| 147 | } |
||
| 149 |