| Conditions | 3 |
| Paths | 3 |
| Total Lines | 104 |
| Code Lines | 17 |
| 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 |
||
| 32 | protected function createPreviews( ImageInterface $image, string $domain, string $type ) : array |
||
| 33 | { |
||
| 34 | $list = []; |
||
| 35 | $config = $this->context()->config(); |
||
| 36 | |||
| 37 | /** mshop/media/manager/previews/common |
||
| 38 | * Scaling options for preview images |
||
| 39 | * |
||
| 40 | * For responsive images, several preview images of different sizes are |
||
| 41 | * generated. This setting controls how many preview images are generated, |
||
| 42 | * what's their maximum width and height and if the given width/height is |
||
| 43 | * enforced by cropping images that doesn't fit. |
||
| 44 | * |
||
| 45 | * The setting must consist of a list image size definitions like: |
||
| 46 | * |
||
| 47 | * [ |
||
| 48 | * ['maxwidth' => 240, 'maxheight' => 320, 'force-size' => true], |
||
| 49 | * ['maxwidth' => 720, 'maxheight' => 960, 'force-size' => false], |
||
| 50 | * ['maxwidth' => 2160, 'maxheight' => 2880, 'force-size' => false], |
||
| 51 | * ] |
||
| 52 | * |
||
| 53 | * "maxwidth" sets the maximum allowed width of the image whereas |
||
| 54 | * "maxheight" does the same for the maximum allowed height. If both |
||
| 55 | * values are given, the image is scaled proportionally so it fits into |
||
| 56 | * the box defined by both values. In case the image has different |
||
| 57 | * proportions than the specified ones and "force-size" is false, the |
||
| 58 | * image is resized to fit entirely into the specified box. One side of |
||
| 59 | * the image will be shorter than it would be possible by the specified |
||
| 60 | * box. |
||
| 61 | * |
||
| 62 | * If "force-size" is true, scaled images that doesn't fit into the |
||
| 63 | * given maximum width/height are centered and then cropped. By default, |
||
| 64 | * images aren't cropped. |
||
| 65 | * |
||
| 66 | * The values for "maxwidth" and "maxheight" can also be null or not |
||
| 67 | * used. In that case, the width or height or both is unbound. If none |
||
| 68 | * of the values are given, the image won't be scaled at all. If only |
||
| 69 | * one value is set, the image will be scaled exactly to the given width |
||
| 70 | * or height and the other side is scaled proportionally. |
||
| 71 | * |
||
| 72 | * You can also define different preview sizes for different domains (e.g. |
||
| 73 | * for catalog images) and for different types (e.g. catalog stage images). |
||
| 74 | * Use configuration settings like |
||
| 75 | * |
||
| 76 | * mshop/media/manager/previews/previews/<domain>/ |
||
| 77 | * mshop/media/manager/previews/previews/<domain>/<type>/ |
||
| 78 | * |
||
| 79 | * for example: |
||
| 80 | * |
||
| 81 | * mshop/media/manager/previews/catalog/previews => [ |
||
| 82 | * ['maxwidth' => 240, 'maxheight' => 320, 'force-size' => true], |
||
| 83 | * ] |
||
| 84 | * mshop/media/manager/previews/catalog/previews => [ |
||
| 85 | * ['maxwidth' => 400, 'maxheight' => 300, 'force-size' => false] |
||
| 86 | * ] |
||
| 87 | * mshop/media/manager/previews/catalog/stage/previews => [ |
||
| 88 | * ['maxwidth' => 360, 'maxheight' => 320, 'force-size' => true], |
||
| 89 | * ['maxwidth' => 720, 'maxheight' => 480, 'force-size' => true] |
||
| 90 | * ] |
||
| 91 | * |
||
| 92 | * These settings will create two preview images for catalog stage images, |
||
| 93 | * one with a different size for all other catalog images and all images |
||
| 94 | * from other domains will be sized to 240x320px. The available domains |
||
| 95 | * which can have images are: |
||
| 96 | * |
||
| 97 | * * attribute |
||
| 98 | * * catalog |
||
| 99 | * * product |
||
| 100 | * * service |
||
| 101 | * * supplier |
||
| 102 | * |
||
| 103 | * There are a few image types included per domain ("default" is always |
||
| 104 | * available). You can also add your own types in the admin backend and |
||
| 105 | * extend the frontend to display them where you need them. |
||
| 106 | * |
||
| 107 | * @param array List of image size definitions |
||
| 108 | * @category Developer |
||
| 109 | * @category User |
||
| 110 | * @since 2019.07 |
||
| 111 | */ |
||
| 112 | $previews = $config->get( 'mshop/media/manager/previews/common', [] ); |
||
| 113 | $previews = $config->get( 'mshop/media/manager/previews/' . $domain, $previews ); |
||
| 114 | $previews = $config->get( 'mshop/media/manager/previews/' . $domain . '/' . $type, $previews ); |
||
| 115 | |||
| 116 | foreach( $previews as $entry ) |
||
| 117 | { |
||
| 118 | $force = $entry['force-size'] ?? 0; |
||
| 119 | $maxwidth = $entry['maxwidth'] ?? null; |
||
| 120 | $maxheight = $entry['maxheight'] ?? null; |
||
| 121 | $bg = ltrim( $entry['background'] ?? 'ffffffff', '#' ); |
||
| 122 | |||
| 123 | if( $this->call( 'filterPreviews', $image, $domain, $type, $maxwidth, $maxheight, $force ) ) |
||
| 124 | { |
||
| 125 | $file = match( $force ) { |
||
| 126 | 0 => $image->scaleDown( $maxwidth, $maxheight ), |
||
| 127 | 1 => $image->pad( $maxwidth, $maxheight, $bg, 'center' ), |
||
| 128 | 2 => $image->cover( $maxwidth, $maxheight ) |
||
| 129 | }; |
||
| 130 | |||
| 131 | $list[$file->width()] = $file; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | return $list; |
||
| 136 | } |
||
| 200 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths