Conditions | 1 |
Paths | 1 |
Total Lines | 184 |
Code Lines | 127 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
130 | public function nodeValuesProvider() { |
||
131 | $fieldValues = [ |
||
132 | 'body' => [ |
||
133 | 'value' => 'test', |
||
134 | 'summary' => 'test summary', |
||
135 | ], |
||
136 | 'field_text' => ['a', 'b', 'c'], |
||
137 | 'field_boolean' => [TRUE, FALSE], |
||
138 | 'field_link' => [ |
||
139 | [ |
||
140 | 'title' => 'Internal link', |
||
141 | 'uri' => 'internal:/node/1', |
||
142 | 'options' => ['attributes' => ['_target' => 'blank']], |
||
143 | ], [ |
||
144 | 'title' => 'External link', |
||
145 | 'uri' => 'http://drupal.org', |
||
146 | 'options' => ['attributes' => ['_target' => 'blank']], |
||
147 | ], |
||
148 | ], |
||
149 | 'field_integer' => [10, -5], |
||
150 | 'field_float' => [3.14145, -8.8], |
||
151 | 'field_decimal' => [10.5, -17.22], |
||
152 | 'field_datetime' => ['2017-01-01', '1900-01-01'], |
||
153 | 'field_timestamp' => [0, 300], |
||
154 | 'field_email' => ['[email protected]'], |
||
155 | 'field_string' => ['test', '123'], |
||
156 | 'field_reference' => [ |
||
157 | ['target_id' => 1], |
||
158 | ], |
||
159 | 'field_file' => [ |
||
160 | [ |
||
161 | 'target_id' => 1, |
||
162 | 'display' => 0, |
||
163 | 'description' => 'description test 1', |
||
164 | ], |
||
165 | [ |
||
166 | 'target_id' => 2, |
||
167 | 'display' => 1, |
||
168 | 'description' => 'description test 2', |
||
169 | ], |
||
170 | ], |
||
171 | 'field_image' => [ |
||
172 | [ |
||
173 | 'target_id' => 1, |
||
174 | 'alt' => 'alt test 1', |
||
175 | 'title' => 'title test 1', |
||
176 | 'width' => 100, |
||
177 | 'height' => 50, |
||
178 | ], |
||
179 | [ |
||
180 | 'target_id' => 2, |
||
181 | 'alt' => 'alt test 2', |
||
182 | 'title' => 'title test 2', |
||
183 | 'width' => 200, |
||
184 | 'height' => 100, |
||
185 | ], |
||
186 | ], |
||
187 | ]; |
||
188 | |||
189 | $expected = [ |
||
190 | 'nid' => 1, |
||
191 | 'vid' => 1, |
||
192 | 'langcode' => [ |
||
193 | 'value' => 'en', |
||
194 | ], |
||
195 | 'type' => [ |
||
196 | 'targetId' => 'test', |
||
197 | ], |
||
198 | 'uid' => [ |
||
199 | 'targetId' => 0, |
||
200 | 'entity' => NULL, |
||
201 | ], |
||
202 | 'title' => 'Test', |
||
203 | 'status' => 1, |
||
204 | 'promote' => 1, |
||
205 | 'sticky' => 0, |
||
206 | 'revisionTranslationAffected' => 1, |
||
207 | 'body' => [ |
||
208 | 'value' => 'test', |
||
209 | 'summary' => 'test summary', |
||
210 | 'summaryProcessed' => "<p>test summary</p>\n", |
||
211 | 'processed' => "<p>test</p>\n", |
||
212 | 'format' => NULL, |
||
213 | ], |
||
214 | 'fieldText' => [ |
||
215 | ['value' => 'a'], |
||
216 | ['value' => 'b'], |
||
217 | ['value' => 'c'], |
||
218 | ], |
||
219 | 'fieldBoolean' => [ |
||
220 | TRUE, |
||
221 | FALSE, |
||
222 | ], |
||
223 | 'fieldLink' => [ |
||
224 | ['title' => 'Internal link', 'uri' => 'internal:/node/1', 'target' => 'blank', 'url' => ['internal' => '/node/1']], |
||
225 | ['title' => 'External link', 'uri' => 'http://drupal.org', 'target' => 'blank', 'url' => ['external' => 'http://drupal.org']], |
||
226 | ], |
||
227 | 'fieldInteger' => [ |
||
228 | 10, |
||
229 | -5, |
||
230 | ], |
||
231 | 'fieldFloat' => [ |
||
232 | 3.14145, |
||
233 | -8.8, |
||
234 | ], |
||
235 | 'fieldDecimal' => [ |
||
236 | 10.5, |
||
237 | -17.22, |
||
238 | ], |
||
239 | 'fieldDatetime' => [ |
||
240 | ['value' => '2017-01-01'], |
||
241 | ['value' => '1900-01-01'], |
||
242 | ], |
||
243 | 'fieldTimestamp' => [ |
||
244 | 0, |
||
245 | 300, |
||
246 | ], |
||
247 | 'fieldEmail' => ['[email protected]'], |
||
248 | 'fieldString' => [ |
||
249 | 'test', |
||
250 | '123', |
||
251 | ], |
||
252 | 'fieldReference' => [ |
||
253 | [ |
||
254 | 'targetId' => 1, |
||
255 | 'entity' => [ |
||
256 | 'title' => 'Test', |
||
257 | 'fieldReference' => [ |
||
258 | [ |
||
259 | 'targetId' => 1, |
||
260 | 'entity' => [ |
||
261 | 'title' => 'Test', |
||
262 | ], |
||
263 | ], |
||
264 | ], |
||
265 | ], |
||
266 | ], |
||
267 | ], |
||
268 | 'fieldFile' => [ |
||
269 | [ |
||
270 | 'targetId' => 1, |
||
271 | 'display' => 0, |
||
272 | 'description' => 'description test 1', |
||
273 | 'entity' => [ |
||
274 | 'uri' => 'public://example.txt', |
||
275 | ], |
||
276 | ], |
||
277 | [ |
||
278 | 'targetId' => 2, |
||
279 | 'display' => 1, |
||
280 | 'description' => 'description test 2', |
||
281 | 'entity' => [ |
||
282 | 'uri' => 'public://example.png', |
||
283 | ], |
||
284 | ], |
||
285 | ], |
||
286 | 'fieldImage' => [ |
||
287 | [ |
||
288 | 'targetId' => 1, |
||
289 | 'alt' => 'alt test 1', |
||
290 | 'title' => 'title test 1', |
||
291 | 'width' => 100, |
||
292 | 'height' => 50, |
||
293 | 'entity' => [ |
||
294 | 'uri' => 'public://example.txt', |
||
295 | ], |
||
296 | ], |
||
297 | [ |
||
298 | 'targetId' => 2, |
||
299 | 'alt' => 'alt test 2', |
||
300 | 'title' => 'title test 2', |
||
301 | 'width' => 200, |
||
302 | 'height' => 100, |
||
303 | 'entity' => [ |
||
304 | 'uri' => 'public://example.png', |
||
305 | ], |
||
306 | ], |
||
307 | ], |
||
308 | ]; |
||
309 | |||
310 | return [ |
||
311 | [$fieldValues, $expected], |
||
312 | ]; |
||
313 | } |
||
314 | |||
316 |