| Conditions | 1 |
| Paths | 1 |
| Total Lines | 184 |
| Code Lines | 127 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 264 | public function nodeValuesProvider() { |
||
| 265 | $fieldValues = [ |
||
| 266 | 'body' => [ |
||
| 267 | 'value' => 'test', |
||
| 268 | 'summary' => 'test summary', |
||
| 269 | ], |
||
| 270 | 'field_text' => ['a', 'b', 'c'], |
||
| 271 | 'field_boolean' => [TRUE, FALSE], |
||
| 272 | 'field_link' => [ |
||
| 273 | [ |
||
| 274 | 'title' => 'Internal link', |
||
| 275 | 'uri' => 'internal:/node/1', |
||
| 276 | 'options' => ['attributes' => ['_target' => 'blank']], |
||
| 277 | ], [ |
||
| 278 | 'title' => 'External link', |
||
| 279 | 'uri' => 'http://drupal.org', |
||
| 280 | 'options' => ['attributes' => ['_target' => 'blank']], |
||
| 281 | ], |
||
| 282 | ], |
||
| 283 | 'field_integer' => [10, -5], |
||
| 284 | 'field_float' => [3.14145, -8.8], |
||
| 285 | 'field_decimal' => [10.5, -17.22], |
||
| 286 | 'field_datetime' => ['2017-01-01', '1900-01-01'], |
||
| 287 | 'field_timestamp' => [0, 300], |
||
| 288 | 'field_email' => ['[email protected]'], |
||
| 289 | 'field_string' => ['test', '123'], |
||
| 290 | 'field_reference' => [ |
||
| 291 | ['target_id' => 1], |
||
| 292 | ], |
||
| 293 | 'field_file' => [ |
||
| 294 | [ |
||
| 295 | 'target_id' => 1, |
||
| 296 | 'display' => 0, |
||
| 297 | 'description' => 'description test 1', |
||
| 298 | ], |
||
| 299 | [ |
||
| 300 | 'target_id' => 2, |
||
| 301 | 'display' => 1, |
||
| 302 | 'description' => 'description test 2', |
||
| 303 | ], |
||
| 304 | ], |
||
| 305 | 'field_image' => [ |
||
| 306 | [ |
||
| 307 | 'target_id' => 1, |
||
| 308 | 'alt' => 'alt test 1', |
||
| 309 | 'title' => 'title test 1', |
||
| 310 | 'width' => 100, |
||
| 311 | 'height' => 50, |
||
| 312 | ], |
||
| 313 | [ |
||
| 314 | 'target_id' => 2, |
||
| 315 | 'alt' => 'alt test 2', |
||
| 316 | 'title' => 'title test 2', |
||
| 317 | 'width' => 200, |
||
| 318 | 'height' => 100, |
||
| 319 | ], |
||
| 320 | ], |
||
| 321 | ]; |
||
| 322 | |||
| 323 | $expected = [ |
||
| 324 | 'nid' => 1, |
||
| 325 | 'vid' => 1, |
||
| 326 | 'langcode' => [ |
||
| 327 | 'value' => 'en', |
||
| 328 | ], |
||
| 329 | 'type' => [ |
||
| 330 | 'targetId' => 'test', |
||
| 331 | ], |
||
| 332 | 'uid' => [ |
||
| 333 | 'targetId' => 0, |
||
| 334 | 'entity' => NULL, |
||
| 335 | ], |
||
| 336 | 'title' => 'Test', |
||
| 337 | 'status' => TRUE, |
||
| 338 | 'promote' => TRUE, |
||
| 339 | 'sticky' => FALSE, |
||
| 340 | 'revisionTranslationAffected' => TRUE, |
||
| 341 | 'body' => [ |
||
| 342 | 'value' => 'test', |
||
| 343 | 'summary' => 'test summary', |
||
| 344 | 'summaryProcessed' => "<p>test summary</p>\n", |
||
| 345 | 'processed' => "<p>test</p>\n", |
||
| 346 | 'format' => 'null', |
||
| 347 | ], |
||
| 348 | 'fieldText' => [ |
||
| 349 | ['value' => 'a'], |
||
| 350 | ['value' => 'b'], |
||
| 351 | ['value' => 'c'], |
||
| 352 | ], |
||
| 353 | 'fieldBoolean' => [ |
||
| 354 | TRUE, |
||
| 355 | FALSE, |
||
| 356 | ], |
||
| 357 | 'fieldLink' => [ |
||
| 358 | ['title' => 'Internal link', 'uri' => 'internal:/node/1', 'target' => 'blank', 'url' => ['internal' => '/node/1']], |
||
| 359 | ['title' => 'External link', 'uri' => 'http://drupal.org', 'target' => 'blank', 'url' => ['external' => 'http://drupal.org']], |
||
| 360 | ], |
||
| 361 | 'fieldInteger' => [ |
||
| 362 | 10, |
||
| 363 | -5, |
||
| 364 | ], |
||
| 365 | 'fieldFloat' => [ |
||
| 366 | 3.14145, |
||
| 367 | -8.8, |
||
| 368 | ], |
||
| 369 | 'fieldDecimal' => [ |
||
| 370 | 10.5, |
||
| 371 | -17.22, |
||
| 372 | ], |
||
| 373 | 'fieldDatetime' => [ |
||
| 374 | ['value' => '2017-01-01'], |
||
| 375 | ['value' => '1900-01-01'], |
||
| 376 | ], |
||
| 377 | 'fieldTimestamp' => [ |
||
| 378 | 0, |
||
| 379 | 300, |
||
| 380 | ], |
||
| 381 | 'fieldEmail' => ['[email protected]'], |
||
| 382 | 'fieldString' => [ |
||
| 383 | 'test', |
||
| 384 | '123', |
||
| 385 | ], |
||
| 386 | 'fieldReference' => [ |
||
| 387 | [ |
||
| 388 | 'targetId' => 1, |
||
| 389 | 'entity' => [ |
||
| 390 | 'title' => 'Test', |
||
| 391 | 'fieldReference' => [ |
||
| 392 | [ |
||
| 393 | 'targetId' => 1, |
||
| 394 | 'entity' => [ |
||
| 395 | 'title' => 'Test', |
||
| 396 | ], |
||
| 397 | ], |
||
| 398 | ], |
||
| 399 | ], |
||
| 400 | ], |
||
| 401 | ], |
||
| 402 | 'fieldFile' => [ |
||
| 403 | [ |
||
| 404 | 'targetId' => 1, |
||
| 405 | 'display' => 0, |
||
| 406 | 'description' => 'description test 1', |
||
| 407 | 'entity' => [ |
||
| 408 | 'uri' => 'public://example.txt', |
||
| 409 | ], |
||
| 410 | ], |
||
| 411 | [ |
||
| 412 | 'targetId' => 2, |
||
| 413 | 'display' => 1, |
||
| 414 | 'description' => 'description test 2', |
||
| 415 | 'entity' => [ |
||
| 416 | 'uri' => 'public://example.png', |
||
| 417 | ], |
||
| 418 | ], |
||
| 419 | ], |
||
| 420 | 'fieldImage' => [ |
||
| 421 | [ |
||
| 422 | 'targetId' => 1, |
||
| 423 | 'alt' => 'alt test 1', |
||
| 424 | 'title' => 'title test 1', |
||
| 425 | 'width' => 100, |
||
| 426 | 'height' => 50, |
||
| 427 | 'entity' => [ |
||
| 428 | 'uri' => 'public://example.txt', |
||
| 429 | ], |
||
| 430 | ], |
||
| 431 | [ |
||
| 432 | 'targetId' => 2, |
||
| 433 | 'alt' => 'alt test 2', |
||
| 434 | 'title' => 'title test 2', |
||
| 435 | 'width' => 200, |
||
| 436 | 'height' => 100, |
||
| 437 | 'entity' => [ |
||
| 438 | 'uri' => 'public://example.png', |
||
| 439 | ], |
||
| 440 | ], |
||
| 441 | ], |
||
| 442 | ]; |
||
| 443 | |||
| 444 | return [ |
||
| 445 | [$fieldValues, $expected], |
||
| 446 | ]; |
||
| 447 | } |
||
| 448 | |||
| 450 |