Conditions | 5 |
Paths | 5 |
Total Lines | 56 |
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 |
||
39 | function embed_longtext_menu($hook, $type, $items, $vars) { |
||
40 | |||
41 | if (elgg_get_context() == 'embed') { |
||
42 | return $items; |
||
43 | } |
||
44 | |||
45 | $url = 'embed'; |
||
46 | |||
47 | $page_owner = elgg_get_page_owner_entity(); |
||
48 | if (elgg_instanceof($page_owner, 'group') && $page_owner->isMember()) { |
||
49 | $url = 'embed?container_guid=' . $page_owner->getGUID(); |
||
50 | } |
||
51 | |||
52 | elgg_load_js('lightbox'); |
||
53 | elgg_load_css('lightbox'); |
||
54 | elgg_require_js('jquery.form'); |
||
55 | elgg_load_js('elgg.embed'); |
||
56 | |||
57 | $text = elgg_echo('embed:media'); |
||
58 | |||
59 | // if loaded through ajax (like on /activity), pull in JS libs manually |
||
60 | // hack for #6422 because we haven't converted everything to amd yet |
||
61 | if (elgg_in_context('ajax')) { |
||
62 | $externals = elgg_get_config('externals_map'); |
||
63 | $embed = elgg_extract('elgg.embed', $externals['js']); |
||
64 | $lightbox_js = elgg_extract('lightbox', $externals['js']); |
||
65 | $lightbox_css = elgg_extract('lightbox', $externals['css']); |
||
66 | |||
67 | $text .= <<<___JS |
||
68 | <script> |
||
69 | require(['jquery.form']); |
||
70 | if (typeof $.fancybox === 'undefined') { |
||
71 | $.getScript('$lightbox_js->url'); |
||
72 | $('head').append('<link rel="stylesheet" href="$lightbox_css->url"></link>'); |
||
73 | } |
||
74 | if (typeof elgg.embed === 'undefined') { |
||
75 | $.getScript('$embed->url'); |
||
76 | } |
||
77 | </script> |
||
78 | ___JS; |
||
79 | } |
||
80 | |||
81 | $items[] = ElggMenuItem::factory(array( |
||
82 | 'name' => 'embed', |
||
83 | 'href' => 'javascript:void()', |
||
84 | 'data-colorbox-opts' => json_encode([ |
||
85 | 'href' => elgg_normalize_url($url), |
||
86 | ]), |
||
87 | 'text' => $text, |
||
88 | 'rel' => "embed-lightbox-{$vars['id']}", |
||
89 | 'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}", |
||
90 | 'priority' => 10, |
||
91 | )); |
||
92 | |||
93 | return $items; |
||
94 | } |
||
95 | |||
194 |