Conditions | 11 |
Paths | 11 |
Total Lines | 70 |
Code Lines | 40 |
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 |
||
26 | protected function resolve($source, $arguments, $context, ResolveInfo $resolveInfo) |
||
27 | { |
||
28 | /** @var OptimizedImage $source */ |
||
29 | $fieldName = $resolveInfo->fieldName; |
||
30 | |||
31 | switch ($fieldName) { |
||
32 | // Special-case the `src` field with arguments |
||
33 | case 'src': |
||
34 | $width = $arguments['width'] ?? 0; |
||
35 | |||
36 | return $source->src($width); |
||
37 | break; |
||
38 | |||
39 | // Special-case the `srcWebp` field with arguments |
||
40 | case 'srcWebp': |
||
41 | $width = $arguments['width'] ?? 0; |
||
42 | |||
43 | return $source->srcWebp($width); |
||
44 | break; |
||
45 | |||
46 | // Special-case the `srcset` field with arguments |
||
47 | case 'srcset': |
||
48 | $dpr = $arguments['dpr'] ?? false; |
||
49 | |||
50 | return $source->srcset($dpr); |
||
51 | break; |
||
52 | |||
53 | // Special-case the `srcsetWebp` field with arguments |
||
54 | case 'srcsetWebp': |
||
55 | $dpr = $arguments['dpr'] ?? false; |
||
56 | |||
57 | return $source->srcsetWebp($dpr); |
||
58 | break; |
||
59 | |||
60 | // Special-case the `maxSrcsetWidth` field |
||
61 | case 'maxSrcsetWidth': |
||
62 | return $source->maxSrcsetWidth(); |
||
63 | break; |
||
64 | |||
65 | // Special-case the `placeholderImage` field |
||
66 | case 'placeholderImage': |
||
67 | return $source->placeholderImage(); |
||
68 | break; |
||
69 | |||
70 | // Special-case the `placeholderBox` field |
||
71 | case 'placeholderBox': |
||
72 | $color = $arguments['color'] ?? null; |
||
73 | |||
74 | return $source->placeholderBox($color); |
||
75 | break; |
||
76 | |||
77 | // Special-case the `placeholderSilhouette` field |
||
78 | case 'placeholderSilhouette': |
||
79 | return $source->placeholderSilhouette(); |
||
80 | break; |
||
81 | |||
82 | // Special-case the `srcUrls` field |
||
83 | case 'srcUrls': |
||
84 | $result = []; |
||
85 | foreach ($source->optimizedImageUrls as $width => $url) { |
||
86 | $result[] = ['width' => $width, 'url' => $url]; |
||
87 | } |
||
88 | |||
89 | return $result; |
||
90 | break; |
||
91 | |||
92 | // Default to just returning the field value |
||
93 | default: |
||
94 | return $source[$fieldName]; |
||
95 | break; |
||
96 | } |
||
99 |