| Conditions | 3 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 15 |
| 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 |
||
| 29 | function url(string $imageUrl, array $args = [], bool $useHttps = true, string $signKey = ''): string |
||
| 30 | { |
||
| 31 | $requiresProcessing = strpos($imageUrl, wp_upload_dir()['baseurl']) === 0; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Control whether the given image url is processable. |
||
| 35 | * |
||
| 36 | * @param bool $isProcessable |
||
| 37 | * @param string $imageUrl |
||
| 38 | * @param array $args |
||
| 39 | */ |
||
| 40 | $isProcessable = apply_filters('helick_imgix_image_url_processable', true, $imageUrl, $args); |
||
| 41 | $isProcessable = (bool)$isProcessable; |
||
| 42 | |||
| 43 | if (!$requiresProcessing || !$isProcessable) { |
||
| 44 | return $imageUrl; |
||
| 45 | } |
||
| 46 | |||
| 47 | $imageUrlPath = parse_url($imageUrl, PHP_URL_PATH); |
||
| 48 | |||
| 49 | $imageFile = basename($imageUrlPath); |
||
| 50 | $imageFile = urlencode($imageFile); |
||
| 51 | |||
| 52 | $imageUrlPath = str_replace($imageUrl, $imageFile, $imageUrlPath); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Control the imgix image url path. |
||
| 56 | * |
||
| 57 | * @param string $imageUrlPath |
||
| 58 | * @param array $args |
||
| 59 | */ |
||
| 60 | $imageUrlPath = apply_filters('helick_imgix_image_url_path', $imageUrlPath, $args); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Control the imgix arguments. |
||
| 64 | * |
||
| 65 | * @param array $args |
||
| 66 | * @param string $imageUrlPath |
||
| 67 | */ |
||
| 68 | $args = apply_filters('helick_imgix_args', $args, $imageUrlPath); |
||
| 69 | |||
| 70 | $urlBuilder = new UrlBuilder(domain(), $useHttps, $signKey); |
||
| 71 | $imgixUrl = $urlBuilder->createURL($imageUrlPath, $args); |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Control the imgix url. |
||
| 75 | * |
||
| 76 | * @param string $imgixUrl |
||
| 77 | * @param string $imageUrl |
||
| 78 | * @param array $args |
||
| 79 | */ |
||
| 80 | $imgixUrl = apply_filters('helick_imgix_url', $imgixUrl, $imageUrl, $args); |
||
| 81 | |||
| 82 | return $imgixUrl; |
||
| 83 | } |
||
| 84 |