Conditions | 1 |
Paths | 1 |
Total Lines | 115 |
Code Lines | 5 |
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 |
||
55 | public function testPrintsKitchenSink() : void |
||
56 | { |
||
57 | $kitchenSink = file_get_contents(__DIR__ . '/schema-kitchen-sink.graphql'); |
||
58 | |||
59 | $ast = Parser::parse($kitchenSink); |
||
60 | $printed = Printer::doPrint($ast); |
||
61 | |||
62 | $expected = 'schema { |
||
63 | query: QueryType |
||
64 | mutation: MutationType |
||
65 | } |
||
66 | |||
67 | """ |
||
68 | This is a description |
||
69 | of the `Foo` type. |
||
70 | """ |
||
71 | type Foo implements Bar & Baz { |
||
72 | one: Type |
||
73 | two(argument: InputType!): Type |
||
74 | three(argument: InputType, other: String): Int |
||
75 | four(argument: String = "string"): String |
||
76 | five(argument: [String] = ["string", "string"]): String |
||
77 | six(argument: InputType = {key: "value"}): Type |
||
78 | seven(argument: Int = null): Type |
||
79 | } |
||
80 | |||
81 | type AnnotatedObject @onObject(arg: "value") { |
||
82 | annotatedField(arg: Type = "default" @onArg): Type @onField |
||
83 | } |
||
84 | |||
85 | type UndefinedType |
||
86 | |||
87 | extend type Foo { |
||
88 | seven(argument: [String]): Type |
||
89 | } |
||
90 | |||
91 | extend type Foo @onType |
||
92 | |||
93 | interface Bar { |
||
94 | one: Type |
||
95 | four(argument: String = "string"): String |
||
96 | } |
||
97 | |||
98 | interface AnnotatedInterface @onInterface { |
||
99 | annotatedField(arg: Type @onArg): Type @onField |
||
100 | } |
||
101 | |||
102 | interface UndefinedInterface |
||
103 | |||
104 | extend interface Bar { |
||
105 | two(argument: InputType!): Type |
||
106 | } |
||
107 | |||
108 | extend interface Bar @onInterface |
||
109 | |||
110 | union Feed = Story | Article | Advert |
||
111 | |||
112 | union AnnotatedUnion @onUnion = A | B |
||
113 | |||
114 | union AnnotatedUnionTwo @onUnion = A | B |
||
115 | |||
116 | union UndefinedUnion |
||
117 | |||
118 | extend union Feed = Photo | Video |
||
119 | |||
120 | extend union Feed @onUnion |
||
121 | |||
122 | scalar CustomScalar |
||
123 | |||
124 | scalar AnnotatedScalar @onScalar |
||
125 | |||
126 | extend scalar CustomScalar @onScalar |
||
127 | |||
128 | enum Site { |
||
129 | DESKTOP |
||
130 | MOBILE |
||
131 | } |
||
132 | |||
133 | enum AnnotatedEnum @onEnum { |
||
134 | ANNOTATED_VALUE @onEnumValue |
||
135 | OTHER_VALUE |
||
136 | } |
||
137 | |||
138 | enum UndefinedEnum |
||
139 | |||
140 | extend enum Site { |
||
141 | VR |
||
142 | } |
||
143 | |||
144 | extend enum Site @onEnum |
||
145 | |||
146 | input InputType { |
||
147 | key: String! |
||
148 | answer: Int = 42 |
||
149 | } |
||
150 | |||
151 | input AnnotatedInput @onInputObject { |
||
152 | annotatedField: Type @onField |
||
153 | } |
||
154 | |||
155 | input UndefinedInput |
||
156 | |||
157 | extend input InputType { |
||
158 | other: Float = 1.23e4 |
||
159 | } |
||
160 | |||
161 | extend input InputType @onInputObject |
||
162 | |||
163 | directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT |
||
164 | |||
165 | directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT |
||
166 | |||
167 | directive @include2(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT |
||
168 | '; |
||
169 | $this->assertEquals($expected, $printed); |
||
170 | } |
||
172 |