Conditions | 10 |
Paths | 24 |
Total Lines | 101 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
20 | public function main($id, $mode) |
||
|
|||
21 | { |
||
22 | global $phpbb_container; |
||
23 | |||
24 | /** @var \phpbb\cache\driver\driver_interface $cache */ |
||
25 | $cache = $phpbb_container->get('cache'); |
||
26 | |||
27 | /** @var \phpbb\config\config $config */ |
||
28 | $config = $phpbb_container->get('config'); |
||
29 | |||
30 | /** @var \phpbb\request\request $request */ |
||
31 | $request = $phpbb_container->get('request'); |
||
32 | |||
33 | /** @var \phpbb\template\template $template */ |
||
34 | $template = $phpbb_container->get('template'); |
||
35 | |||
36 | /** @var \phpbb\language\language $language */ |
||
37 | $language = $phpbb_container->get('language'); |
||
38 | $language->add_lang('acp', 'phpbb/mediaembed'); |
||
39 | |||
40 | $form_key = 'phpbb/mediaembed'; |
||
41 | add_form_key($form_key); |
||
42 | |||
43 | switch ($mode) |
||
44 | { |
||
45 | case 'manage': |
||
46 | |||
47 | $this->tpl_name = 'acp_phpbb_mediaembed_manage'; |
||
48 | $this->page_title = $language->lang('ACP_MEDIA_MANAGE'); |
||
49 | |||
50 | /** @var \phpbb\config\db_text $config_text */ |
||
51 | $config_text = $phpbb_container->get('config_text'); |
||
52 | |||
53 | if ($request->is_set_post('submit')) |
||
54 | { |
||
55 | if (!check_form_key($form_key)) |
||
56 | { |
||
57 | trigger_error('FORM_INVALID'); |
||
58 | } |
||
59 | |||
60 | $config_text->set('media_embed_sites', json_encode($request->variable('mark', ['']))); |
||
61 | |||
62 | $cache->destroy($phpbb_container->getParameter('text_formatter.cache.parser.key')); |
||
63 | $cache->destroy($phpbb_container->getParameter('text_formatter.cache.renderer.key')); |
||
64 | |||
65 | trigger_error($language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); |
||
66 | } |
||
67 | |||
68 | $sites = []; |
||
69 | |||
70 | $allowed_sites = $config_text->get('media_embed_sites'); |
||
71 | $allowed_sites = $allowed_sites ? json_decode($allowed_sites, true) : []; |
||
72 | |||
73 | /** @var \s9e\TextFormatter\Configurator $configurator */ |
||
74 | $configurator = $phpbb_container->get('text_formatter.s9e.factory')->get_configurator(); |
||
75 | foreach ($configurator->MediaEmbed->defaultSites->getIds() as $siteId) |
||
76 | { |
||
77 | if (isset($configurator->BBCodes[$siteId])) |
||
78 | { |
||
79 | continue; |
||
80 | } |
||
81 | |||
82 | $sites[] = [ |
||
83 | 'name' => $siteId, |
||
84 | 'checked' => in_array($siteId, $allowed_sites), |
||
85 | ]; |
||
86 | } |
||
87 | |||
88 | $template->assign_vars([ |
||
89 | 'U_ACTION' => $this->u_action, |
||
90 | 'MEDIA_SITES' => $sites, |
||
91 | ]); |
||
92 | |||
93 | break; |
||
94 | |||
95 | case 'settings': |
||
96 | default: |
||
97 | |||
98 | $this->tpl_name = 'acp_phpbb_mediaembed_settings'; |
||
99 | $this->page_title = $language->lang('ACP_MEDIA_SETTINGS'); |
||
100 | |||
101 | if ($request->is_set_post('submit')) |
||
102 | { |
||
103 | if (!check_form_key($form_key)) |
||
104 | { |
||
105 | trigger_error('FORM_INVALID'); |
||
106 | } |
||
107 | |||
108 | $config->set('media_embed_bbcode', $request->variable('media_embed_bbcode', 0)); |
||
109 | |||
110 | trigger_error($language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); |
||
111 | } |
||
112 | |||
113 | $template->assign_vars([ |
||
114 | 'U_ACTION' => $this->u_action, |
||
115 | 'S_MEDIA_EMBED_BBCODE' => $config['media_embed_bbcode'], |
||
116 | ]); |
||
117 | |||
118 | break; |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.