| Conditions | 16 |
| Paths | 104 |
| Total Lines | 71 |
| Code Lines | 39 |
| 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 | public static function handle_shortcode($args, $content, $parser, $shortcode, $extra = array()) |
||
| 27 | { |
||
| 28 | $cache = static::getCache(); |
||
| 29 | $cacheKey = static::getCacheKey($args); |
||
| 30 | |||
| 31 | $item = $cache->get($cacheKey); |
||
| 32 | if ($item) { |
||
| 33 | /** @var AssetStore $store */ |
||
| 34 | $store = Injector::inst()->get(AssetStore::class); |
||
| 35 | if (!empty($item['filename'])) { |
||
| 36 | $store->grant($item['filename'], $item['hash']); |
||
| 37 | } |
||
| 38 | return $item['markup']; |
||
| 39 | } |
||
| 40 | |||
| 41 | // Find appropriate record, with fallback for error handlers |
||
| 42 | $record = static::find_shortcode_record($args, $errorCode); |
||
| 43 | if ($errorCode) { |
||
| 44 | $record = static::find_error_record($errorCode); |
||
| 45 | } |
||
| 46 | if (!$record) { |
||
| 47 | return null; // There were no suitable matches at all. |
||
| 48 | } |
||
| 49 | |||
| 50 | // Check if a resize is required |
||
| 51 | $src = $record->Link(); |
||
| 52 | $micro_url = false; |
||
| 53 | if ($record instanceof Image) { |
||
| 54 | $width = isset($args['width']) ? $args['width'] : null; |
||
| 55 | $height = isset($args['height']) ? $args['height'] : null; |
||
| 56 | $hasCustomDimensions = ($width && $height); |
||
| 57 | if ($hasCustomDimensions && (($width != $record->getWidth()) || ($height != $record->getHeight()))) { |
||
| 58 | $resized = $record->ResizedImage($width, $height); |
||
| 59 | // Make sure that the resized image actually returns an image |
||
| 60 | if (!empty($resized)) { |
||
| 61 | $src = $resized->getURL(); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | $micro_url = $record->MicroImage()->getURL(); |
||
| 65 | } |
||
| 66 | |||
| 67 | // Build the HTML tag |
||
| 68 | $attrs = array_merge( |
||
| 69 | // Set overrideable defaults |
||
| 70 | ['src' => '', 'alt' => $record->Title], |
||
| 71 | // Use all other shortcode arguments |
||
| 72 | $args, |
||
| 73 | // But enforce some values |
||
| 74 | ['id' => '', 'src' => $src] |
||
| 75 | ); |
||
| 76 | |||
| 77 | // Clean out any empty attributes |
||
| 78 | $attrs = array_filter($attrs, function ($v) { |
||
| 79 | return (bool)$v; |
||
| 80 | }); |
||
| 81 | |||
| 82 | if ($micro_url) { |
||
| 83 | $attrs['data-src'] = $src; |
||
| 84 | $attrs['src'] = $micro_url; |
||
| 85 | } |
||
| 86 | |||
| 87 | $markup = HTML::createTag('img', $attrs); |
||
| 88 | |||
| 89 | // cache it for future reference |
||
| 90 | $cache->set($cacheKey, [ |
||
| 91 | 'markup' => $markup, |
||
| 92 | 'filename' => $record instanceof File ? $record->getFilename() : null, |
||
| 93 | 'hash' => $record instanceof File ? $record->getHash() : null, |
||
| 94 | ]); |
||
| 95 | |||
| 96 | return $markup; |
||
| 97 | } |
||
| 98 | } |
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