Conditions | 15 |
Paths | 289 |
Total Lines | 106 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
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 |
||
34 | public function main($id, $mode) |
||
|
|||
35 | { |
||
36 | global $phpbb_container; |
||
37 | |||
38 | /** @var \phpbb\config\config $config Config object */ |
||
39 | $config = $phpbb_container->get('config'); |
||
40 | |||
41 | /** @var \phpbb\language\language $language Language object */ |
||
42 | $language = $phpbb_container->get('language'); |
||
43 | |||
44 | /** @var \phpbb\request\request $request Request object */ |
||
45 | $request = $phpbb_container->get('request'); |
||
46 | |||
47 | /** @var \phpbb\template\template $template Template object */ |
||
48 | $template = $phpbb_container->get('template'); |
||
49 | |||
50 | $language->add_lang('viglink_module_acp', 'phpbb/viglink'); |
||
51 | |||
52 | $this->tpl_name = 'acp_viglink'; |
||
53 | $this->page_title = $language->lang('ACP_VIGLINK_SETTINGS'); |
||
54 | |||
55 | $submit = $request->is_set_post('submit'); |
||
56 | |||
57 | if ($mode !== 'settings') |
||
58 | { |
||
59 | return; |
||
60 | } |
||
61 | |||
62 | $form_key = 'acp_viglink'; |
||
63 | add_form_key($form_key); |
||
64 | |||
65 | $error = array(); |
||
66 | |||
67 | // Get stored config/default values |
||
68 | $cfg_array = array( |
||
69 | 'viglink_enabled' => isset($config['viglink_enabled']) ? $config['viglink_enabled'] : 0, |
||
70 | ); |
||
71 | |||
72 | // Error if the form is invalid |
||
73 | if ($submit && !check_form_key($form_key)) |
||
74 | { |
||
75 | $error[] = $language->lang('FORM_INVALID'); |
||
76 | } |
||
77 | |||
78 | // Do not process form if invalid |
||
79 | if (count($error)) |
||
80 | { |
||
81 | $submit = false; |
||
82 | } |
||
83 | |||
84 | if ($submit) |
||
85 | { |
||
86 | // Get the VigLink form field values |
||
87 | $cfg_array['viglink_enabled'] = $request->variable('viglink_enabled', 0); |
||
88 | |||
89 | // If no errors, set the config values |
||
90 | if (!count($error)) |
||
91 | { |
||
92 | foreach ($cfg_array as $cfg => $value) |
||
93 | { |
||
94 | $config->set($cfg, $value); |
||
95 | } |
||
96 | |||
97 | trigger_error($language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | if (!isset($config['questionnaire_unique_id'])) |
||
102 | { |
||
103 | $config->set('questionnaire_unique_id', unique_id()); |
||
104 | } |
||
105 | |||
106 | // Set a general error message if VigLink has been disabled by phpBB |
||
107 | if (!$config['allow_viglink_phpbb']) |
||
108 | { |
||
109 | $error[] = $language->lang('ACP_VIGLINK_DISABLED_PHPBB'); |
||
110 | } |
||
111 | |||
112 | // Try to get convert account key from .com |
||
113 | $sub_id = md5($config['viglink_api_siteid'] . $config['questionnaire_unique_id']); |
||
114 | $convert_account_link = $config->offsetGet('viglink_convert_account_url'); |
||
115 | |||
116 | if (empty($convert_account_link) || strpos($config['viglink_convert_account_url'], 'subId=' . $sub_id) === false) |
||
117 | { |
||
118 | $convert_account_link = @file_get_contents('https://www.phpbb.com/viglink/convert?domain=' . urlencode($config['server_name']) . '&siteid=' . $config['viglink_api_siteid'] . '&uuid=' . $config['questionnaire_unique_id'] . '&key=' . $config['phpbb_viglink_api_key']); |
||
119 | if (!empty($convert_account_link) && strpos($convert_account_link, 'https://www.viglink.com/users/convertAccount') === 0) |
||
120 | { |
||
121 | $type_caster = new type_cast_helper(); |
||
122 | $type_caster->set_var($convert_account_link, $convert_account_link, 'string', false, false); |
||
123 | $config->set('viglink_convert_account_url', $convert_account_link); |
||
124 | } |
||
125 | else |
||
126 | { |
||
127 | $error[] = $language->lang('ACP_VIGLINK_NO_CONVERT_LINK'); |
||
128 | $convert_account_link = ''; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | $template->assign_vars(array( |
||
133 | 'S_ERROR' => (bool) count($error), |
||
134 | 'ERROR_MSG' => implode('<br />', $error), |
||
135 | |||
136 | 'VIGLINK_ENABLED' => $cfg_array['viglink_enabled'], |
||
137 | |||
138 | 'U_VIGLINK_CONVERT' => $convert_account_link, |
||
139 | 'U_ACTION' => $this->u_action, |
||
140 | )); |
||
143 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.