| Conditions | 12 |
| Paths | 289 |
| Total Lines | 55 |
| Code Lines | 30 |
| 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 |
||
| 49 | public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array()) |
||
| 50 | { |
||
| 51 | // Get service URL |
||
| 52 | if (!empty($content)) { |
||
| 53 | $serviceURL = $content; |
||
| 54 | } elseif (!empty($arguments['url'])) { |
||
| 55 | $serviceURL = $arguments['url']; |
||
| 56 | } else { |
||
| 57 | return ''; |
||
| 58 | } |
||
| 59 | |||
| 60 | // See https://github.com/oscarotero/Embed#example-with-all-options for service arguments |
||
| 61 | $serviceArguments = []; |
||
| 62 | if (!empty($arguments['width'])) { |
||
| 63 | $serviceArguments['min_image_width'] = $arguments['width']; |
||
| 64 | } |
||
| 65 | if (!empty($arguments['height'])) { |
||
| 66 | $serviceArguments['min_image_height'] = $arguments['height']; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** @var EmbedResource $embed */ |
||
| 70 | $embed = Injector::inst()->create(Embeddable::class, $serviceURL); |
||
| 71 | if (!empty($serviceArguments)) { |
||
| 72 | $embed->setOptions(array_merge($serviceArguments, (array) $embed->getOptions())); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Allow resolver to be mocked |
||
| 76 | $dispatcher = null; |
||
| 77 | if (isset($extra['resolver'])) { |
||
| 78 | $dispatcher = Injector::inst()->create( |
||
| 79 | $extra['resolver']['class'], |
||
| 80 | $serviceURL, |
||
| 81 | $extra['resolver']['config'] |
||
| 82 | ); |
||
| 83 | } elseif (Injector::inst()->has(DispatcherInterface::class)) { |
||
| 84 | $dispatcher = Injector::inst()->get(DispatcherInterface::class); |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($dispatcher) { |
||
|
|
|||
| 88 | $embed->setDispatcher($dispatcher); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Process embed |
||
| 92 | $embed = $embed->getEmbed(); |
||
| 93 | |||
| 94 | // Convert embed object into HTML |
||
| 95 | if ($embed && $embed instanceof Adapter) { |
||
| 96 | $result = static::embedForTemplate($embed, $arguments); |
||
| 97 | if ($result) { |
||
| 98 | return $result; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | // Fallback to link to service |
||
| 103 | return static::linkEmbed($arguments, $serviceURL, $serviceURL); |
||
| 104 | } |
||
| 216 |