| Conditions | 1 |
| Paths | 1 |
| Total Lines | 190 |
| Code Lines | 132 |
| 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 |
||
| 57 | public function setUp() |
||
| 58 | { |
||
| 59 | $this->node = new InterfaceType([ |
||
| 60 | 'name' => 'Node', |
||
| 61 | 'fields' => [ |
||
| 62 | 'id' => Type::string(), |
||
| 63 | ], |
||
| 64 | ]); |
||
| 65 | |||
| 66 | $this->content = new InterfaceType([ |
||
| 67 | 'name' => 'Content', |
||
| 68 | 'fields' => function () { |
||
| 69 | return [ |
||
| 70 | 'title' => Type::string(), |
||
| 71 | 'body' => Type::string(), |
||
| 72 | 'author' => $this->user, |
||
| 73 | 'comments' => Type::listOf($this->comment), |
||
| 74 | 'categories' => Type::listOf($this->category), |
||
| 75 | ]; |
||
| 76 | }, |
||
| 77 | ]); |
||
| 78 | |||
| 79 | $this->blogStory = new ObjectType([ |
||
| 80 | 'name' => 'BlogStory', |
||
| 81 | 'interfaces' => [ |
||
| 82 | $this->node, |
||
| 83 | $this->content, |
||
| 84 | ], |
||
| 85 | 'fields' => function () { |
||
| 86 | return [ |
||
| 87 | $this->node->getField('id'), |
||
| 88 | $this->content->getField('title'), |
||
| 89 | $this->content->getField('body'), |
||
| 90 | $this->content->getField('author'), |
||
| 91 | $this->content->getField('comments'), |
||
| 92 | $this->content->getField('categories'), |
||
| 93 | ]; |
||
| 94 | }, |
||
| 95 | ]); |
||
| 96 | |||
| 97 | new ObjectType([ |
||
| 98 | 'name' => 'Link', |
||
| 99 | 'interfaces' => [ |
||
| 100 | $this->node, |
||
| 101 | $this->content, |
||
| 102 | ], |
||
| 103 | 'fields' => function () { |
||
| 104 | return [ |
||
| 105 | 'id' => $this->node->getField('id'), |
||
| 106 | 'title' => $this->content->getField('title'), |
||
| 107 | 'body' => $this->content->getField('body'), |
||
| 108 | 'author' => $this->content->getField('author'), |
||
| 109 | 'comments' => $this->content->getField('comments'), |
||
| 110 | 'categories' => $this->content->getField('categories'), |
||
| 111 | 'url' => Type::string(), |
||
| 112 | ]; |
||
| 113 | }, |
||
| 114 | ]); |
||
| 115 | |||
| 116 | new ObjectType([ |
||
| 117 | 'name' => 'Video', |
||
| 118 | 'interfaces' => [ |
||
| 119 | $this->node, |
||
| 120 | $this->content, |
||
| 121 | ], |
||
| 122 | 'fields' => function () { |
||
| 123 | return [ |
||
| 124 | 'id' => $this->node->getField('id'), |
||
| 125 | 'title' => $this->content->getField('title'), |
||
| 126 | 'body' => $this->content->getField('body'), |
||
| 127 | 'author' => $this->content->getField('author'), |
||
| 128 | 'comments' => $this->content->getField('comments'), |
||
| 129 | 'categories' => $this->content->getField('categories'), |
||
| 130 | 'streamUrl' => Type::string(), |
||
| 131 | 'downloadUrl' => Type::string(), |
||
| 132 | 'metadata' => new ObjectType([ |
||
| 133 | 'name' => 'VideoMetadata', |
||
| 134 | 'fields' => [ |
||
| 135 | 'lat' => Type::float(), |
||
| 136 | 'lng' => Type::float(), |
||
| 137 | ], |
||
| 138 | ]), |
||
| 139 | ]; |
||
| 140 | }, |
||
| 141 | ]); |
||
| 142 | |||
| 143 | $this->comment = new ObjectType([ |
||
| 144 | 'name' => 'Comment', |
||
| 145 | 'interfaces' => [ |
||
| 146 | $this->node, |
||
| 147 | ], |
||
| 148 | 'fields' => function () { |
||
| 149 | return [ |
||
| 150 | 'id' => $this->node->getField('id'), |
||
| 151 | 'author' => $this->user, |
||
| 152 | 'text' => Type::string(), |
||
| 153 | 'replies' => Type::listOf($this->comment), |
||
| 154 | 'parent' => $this->comment, |
||
| 155 | 'content' => $this->content, |
||
| 156 | ]; |
||
| 157 | }, |
||
| 158 | ]); |
||
| 159 | |||
| 160 | $this->user = new ObjectType([ |
||
| 161 | 'name' => 'User', |
||
| 162 | 'interfaces' => [ |
||
| 163 | $this->node, |
||
| 164 | ], |
||
| 165 | 'fields' => function () { |
||
| 166 | return [ |
||
| 167 | 'id' => $this->node->getField('id'), |
||
| 168 | 'name' => Type::string(), |
||
| 169 | ]; |
||
| 170 | }, |
||
| 171 | ]); |
||
| 172 | |||
| 173 | $this->category = new ObjectType([ |
||
| 174 | 'name' => 'Category', |
||
| 175 | 'interfaces' => [ |
||
| 176 | $this->node, |
||
| 177 | ], |
||
| 178 | 'fields' => function () { |
||
| 179 | return [ |
||
| 180 | 'id' => $this->node->getField('id'), |
||
| 181 | 'name' => Type::string(), |
||
| 182 | ]; |
||
| 183 | }, |
||
| 184 | ]); |
||
| 185 | |||
| 186 | $this->mention = new UnionType([ |
||
| 187 | 'name' => 'Mention', |
||
| 188 | 'types' => [ |
||
| 189 | $this->user, |
||
| 190 | $this->category, |
||
| 191 | ], |
||
| 192 | ]); |
||
| 193 | |||
| 194 | $this->query = new ObjectType([ |
||
| 195 | 'name' => 'Query', |
||
| 196 | 'fields' => [ |
||
| 197 | 'viewer' => $this->user, |
||
| 198 | 'latestContent' => $this->content, |
||
| 199 | 'node' => $this->node, |
||
| 200 | 'mentions' => Type::listOf($this->mention), |
||
| 201 | ], |
||
| 202 | ]); |
||
| 203 | |||
| 204 | $this->postStoryMutationInput = new InputObjectType([ |
||
| 205 | 'name' => 'PostStoryMutationInput', |
||
| 206 | 'fields' => [ |
||
| 207 | 'title' => Type::string(), |
||
| 208 | 'body' => Type::string(), |
||
| 209 | 'author' => Type::id(), |
||
| 210 | 'category' => Type::id(), |
||
| 211 | ], |
||
| 212 | ]); |
||
| 213 | |||
| 214 | $this->mutation = new ObjectType([ |
||
| 215 | 'name' => 'Mutation', |
||
| 216 | 'fields' => [ |
||
| 217 | 'postStory' => [ |
||
| 218 | 'type' => $this->postStoryMutation = new ObjectType([ |
||
| 219 | 'name' => 'PostStoryMutation', |
||
| 220 | 'fields' => [ |
||
| 221 | 'story' => $this->blogStory, |
||
| 222 | ], |
||
| 223 | ]), |
||
| 224 | 'args' => [ |
||
| 225 | 'input' => Type::nonNull($this->postStoryMutationInput), |
||
| 226 | 'clientRequestId' => Type::string(), |
||
| 227 | ], |
||
| 228 | ], |
||
| 229 | 'postComment' => [ |
||
| 230 | 'type' => $this->postCommentMutation = new ObjectType([ |
||
| 231 | 'name' => 'PostCommentMutation', |
||
| 232 | 'fields' => [ |
||
| 233 | 'comment' => $this->comment, |
||
| 234 | ], |
||
| 235 | ]), |
||
| 236 | 'args' => [ |
||
| 237 | 'input' => Type::nonNull($this->postCommentMutationInput = new InputObjectType([ |
||
| 238 | 'name' => 'PostCommentMutationInput', |
||
| 239 | 'fields' => [ |
||
| 240 | 'text' => Type::nonNull(Type::string()), |
||
| 241 | 'author' => Type::nonNull(Type::id()), |
||
| 242 | 'content' => Type::id(), |
||
| 243 | 'parent' => Type::id(), |
||
| 244 | ], |
||
| 245 | ])), |
||
| 246 | 'clientRequestId' => Type::string(), |
||
| 247 | ], |
||
| 312 |