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