| Conditions | 12 | 
| Paths | 120 | 
| Total Lines | 64 | 
| Code Lines | 32 | 
| 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  | 
            ||
| 98 | private static function getUrlBuilderForTransform(Asset $asset, $transform, array $params = []): UrlBuilder  | 
            ||
| 99 |     { | 
            ||
| 100 | $assetUri = self::getAssetUri($asset);  | 
            ||
| 101 | $baseUrl = $params['baseUrl'];  | 
            ||
| 102 | $securityKey = $params['securityKey'] ?: null;  | 
            ||
| 103 | $builder = UrlBuilder::construct($baseUrl, $securityKey, $assetUri);  | 
            ||
| 104 | $settings = ImageOptimize::$plugin->getSettings();  | 
            ||
| 105 | |||
| 106 |         if ($transform->mode === 'fit') { | 
            ||
| 107 | |||
| 108 | // https://thumbor.readthedocs.io/en/latest/usage.html#fit-in  | 
            ||
| 109 | $builder->fitIn($transform->width, $transform->height);  | 
            ||
| 110 |         } elseif ($transform->mode === 'stretch') { | 
            ||
| 111 | $builder  | 
            ||
| 112 | ->resize($transform->width, $transform->height)  | 
            ||
| 113 |                 ->addFilter('upscale'); | 
            ||
| 114 | |||
| 115 | // https://github.com/thumbor/thumbor/issues/1123  | 
            ||
| 116 |             Craft::warning('Thumbor has no equivalent to the "stretch" transform mode. The resulting image will be resized and cropped, but not stretched.', __METHOD__); | 
            ||
| 117 |         } else { | 
            ||
| 118 | |||
| 119 | // https://thumbor.readthedocs.io/en/latest/usage.html#image-size  | 
            ||
| 120 | $builder->resize($transform->width, $transform->height);  | 
            ||
| 121 | |||
| 122 |             if ($focalPoint = self::getFocalPoint($asset)) { | 
            ||
| 123 | |||
| 124 | // https://thumbor.readthedocs.io/en/latest/focal.html  | 
            ||
| 125 |                 $builder->addFilter('focal', $focalPoint); | 
            ||
| 126 |             } elseif (preg_match('/(top|center|bottom)-(left|center|right)/', $transform->position, $matches)) { | 
            ||
| 127 |                 $v = str_replace('center', 'middle', $matches[1]); | 
            ||
| 128 | $h = $matches[2];  | 
            ||
| 129 | |||
| 130 | // https://thumbor.readthedocs.io/en/latest/usage.html#horizontal-align  | 
            ||
| 131 | $builder->valign($v)->halign($h);  | 
            ||
| 132 | }  | 
            ||
| 133 | }  | 
            ||
| 134 | |||
| 135 | // https://thumbor.readthedocs.io/en/latest/format.html  | 
            ||
| 136 |         if ($format = self::getFormat($transform)) { | 
            ||
| 137 |             $builder->addFilter('format', $format); | 
            ||
| 138 | }  | 
            ||
| 139 | |||
| 140 | // https://thumbor.readthedocs.io/en/latest/quality.html  | 
            ||
| 141 |         if ($quality = self::getQuality($transform)) { | 
            ||
| 142 |             $builder->addFilter('quality', $quality); | 
            ||
| 143 | }  | 
            ||
| 144 | |||
| 145 |         if (property_exists($transform, 'interlace')) { | 
            ||
| 146 |             Craft::warning('Thumbor enables progressive JPEGs on the server-level, not as a request option. See https://thumbor.readthedocs.io/en/latest/jpegtran.html', __METHOD__); | 
            ||
| 147 | }  | 
            ||
| 148 | |||
| 149 |         if ($settings->autoSharpenScaledImages) { | 
            ||
| 150 | |||
| 151 | // See if the image has been scaled >= 50%  | 
            ||
| 152 | $widthScale = $asset->getWidth() / ($transform->width ?? $asset->getWidth());  | 
            ||
| 153 | $heightScale = $asset->getHeight() / ($transform->height ?? $asset->getHeight());  | 
            ||
| 154 |             if (($widthScale >= 2.0) || ($heightScale >= 2.0)) { | 
            ||
| 155 | |||
| 156 | // https://thumbor.readthedocs.io/en/latest/sharpen.html  | 
            ||
| 157 |                 $builder->addFilter('sharpen', .5, .5, 'true'); | 
            ||
| 158 | }  | 
            ||
| 159 | }  | 
            ||
| 160 | |||
| 161 | return $builder;  | 
            ||
| 162 | }  | 
            ||
| 219 |