Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 34 |
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 |
||
37 | public function testImageField() { |
||
38 | $a = $this->createNode([ |
||
39 | 'title' => 'Node A', |
||
40 | 'type' => 'test', |
||
41 | ]); |
||
42 | |||
43 | $a->image->generateSampleItems(1); |
||
44 | |||
45 | $a->save(); |
||
46 | |||
47 | |||
48 | $style = ImageStyle::load('thumbnail'); |
||
49 | |||
50 | $dimensions = [ |
||
51 | 'width' => $a->image[0]->width, |
||
52 | 'height' => $a->image[0]->height, |
||
53 | ]; |
||
54 | |||
55 | $style->transformDimensions($dimensions, $a->image[0]->entity->getFileUri()); |
||
56 | |||
57 | // TODO: Check cache metadata. |
||
58 | $metadata = $this->defaultCacheMetaData(); |
||
59 | $metadata->addCacheTags([ |
||
60 | 'config:field.storage.node.image', |
||
61 | 'entity_bundles', |
||
62 | 'entity_field_info', |
||
63 | 'entity_types', |
||
64 | 'file:1', |
||
65 | 'node:1', |
||
66 | // TODO: missing image style config cache tags? |
||
67 | ]); |
||
68 | |||
69 | $this->assertResults($this->getQueryFromFile('image.gql'), [ |
||
70 | 'path' => '/node/' . $a->id(), |
||
71 | ], [ |
||
72 | 'route' => [ |
||
73 | 'node' => [ |
||
74 | 'image' => [[ |
||
75 | 'alt' => $a->image->alt, |
||
76 | 'title' => $a->image->title, |
||
77 | 'entity' => ['url' => $a->image->entity->url()], |
||
78 | 'width' => $a->image[0]->width, |
||
79 | 'height' => $a->image[0]->height, |
||
80 | 'thumbnailImage' => [ |
||
81 | 'url' => $style->buildUrl($a->image->entity->uri->value), |
||
82 | 'width' => $dimensions['width'], |
||
83 | 'height' => $dimensions['height'], |
||
84 | ], |
||
85 | ]], |
||
86 | ], |
||
87 | ], |
||
88 | ], $metadata); |
||
89 | } |
||
90 | |||
92 |