Conditions | 26 |
Paths | 9216 |
Total Lines | 198 |
Lines | 21 |
Ratio | 10.61 % |
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 |
||
68 | function xoops_module_update_apcal(XoopsModule $module) |
||
69 | { |
||
70 | // global $xoopsDB; |
||
71 | $moduleDirName = basename(dirname(__DIR__)); |
||
72 | $capsDirName = strtoupper($moduleDirName); |
||
73 | |||
74 | View Code Duplication | if (!$GLOBALS['xoopsDB']->queryF("SELECT shortsummary FROM {$GLOBALS['xoopsDB']->prefix('apcal_event')}")) { |
|
75 | if ($GLOBALS['xoopsDB']->queryF("ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_event')} ADD shortsummary VARCHAR(255) AFTER groupid")) { |
||
76 | } |
||
77 | } |
||
78 | $result = $GLOBALS['xoopsDB']->queryF("SELECT id, summary FROM {$GLOBALS['xoopsDB']->prefix('apcal_event')}"); |
||
79 | while ($row = $GLOBALS['xoopsDB']->fetchArray($result)) { |
||
80 | $shortsummary = makeShort($row['summary']); |
||
81 | $GLOBALS['xoopsDB']->queryF("UPDATE {$GLOBALS['xoopsDB']->prefix('apcal_event')} SET shortsummary='{$shortsummary}' WHERE id={$row['id']}"); |
||
82 | } |
||
83 | |||
84 | View Code Duplication | if (!$GLOBALS['xoopsDB']->queryF("SELECT cat_shorttitle FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')}")) { |
|
85 | if ($GLOBALS['xoopsDB']->queryF("ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_cat')} ADD cat_shorttitle VARCHAR(255) AFTER enabled")) { |
||
86 | } |
||
87 | } |
||
88 | $result = $GLOBALS['xoopsDB']->queryF("SELECT cid, cat_title FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')}"); |
||
89 | while ($row = $GLOBALS['xoopsDB']->fetchArray($result)) { |
||
90 | $cat_shorttitle = makeShort($row['cat_title']); |
||
91 | $GLOBALS['xoopsDB']->queryF("UPDATE {$GLOBALS['xoopsDB']->prefix('apcal_cat')} SET cat_shorttitle='{$cat_shorttitle}' WHERE cid={$row['cid']}"); |
||
92 | } |
||
93 | |||
94 | if (!$GLOBALS['xoopsDB']->queryF("SELECT email,url,mainCategory, otherHours FROM {$GLOBALS['xoopsDB']->prefix('apcal_event')}")) { |
||
95 | $sql = "ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_event')} "; |
||
96 | $sql .= 'ADD url VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT \'\' AFTER location,'; |
||
97 | $sql .= 'ADD email VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT \'\' AFTER url,'; |
||
98 | $sql .= 'ADD mainCategory SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL DEFAULT \'00000\' AFTER dtstamp,'; |
||
99 | $sql .= 'ADD otherHours VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT \'\' AFTER end'; |
||
100 | $GLOBALS['xoopsDB']->queryF($sql); |
||
101 | } |
||
102 | |||
103 | if (!$GLOBALS['xoopsDB']->queryF("SELECT color,canbemain FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')}")) { |
||
104 | $sql = "ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_cat')} "; |
||
105 | $sql .= 'ADD color VARCHAR( 7 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT \'#5555AA\' AFTER cat_desc,'; |
||
106 | $sql .= 'ADD canbemain TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT \'0\' AFTER autocreated'; |
||
107 | $GLOBALS['xoopsDB']->queryF($sql); |
||
108 | } |
||
109 | |||
110 | $sql = "CREATE TABLE IF NOT EXISTS {$GLOBALS['xoopsDB']->prefix('apcal_pictures')} "; |
||
111 | $sql .= '(id int(10) unsigned NOT NULL AUTO_INCREMENT,'; |
||
112 | $sql .= 'event_id int(10) unsigned zerofill NOT NULL,'; |
||
113 | $sql .= 'picture varchar(255) NOT NULL,'; |
||
114 | $sql .= 'main_pic tinyint(1) unsigned NOT NULL DEFAULT \'0\','; |
||
115 | $sql .= 'PRIMARY KEY (id)) '; |
||
116 | $sql .= 'ENGINE=MyISAM DEFAULT CHARSET=utf8'; |
||
117 | $GLOBALS['xoopsDB']->queryF($sql); |
||
118 | |||
119 | $sql = "CREATE TABLE IF NOT EXISTS {$GLOBALS['xoopsDB']->prefix('apcal_ro_events')} ( |
||
120 | roe_id int(10) unsigned NOT NULL AUTO_INCREMENT, |
||
121 | roe_eventid mediumint(8) unsigned zerofill NOT NULL DEFAULT '00000000', |
||
122 | roe_number int(10) NOT NULL DEFAULT '0', |
||
123 | roe_datelimit int(10) NOT NULL DEFAULT '0', |
||
124 | roe_needconfirm INT(10) NOT NULL DEFAULT '0', |
||
125 | roe_waitinglist INT(10) NOT NULL DEFAULT '0', |
||
126 | roe_submitter int(10) NOT NULL DEFAULT '0', |
||
127 | roe_date_created int(10) NOT NULL DEFAULT '0', |
||
128 | PRIMARY KEY (roe_id), |
||
129 | KEY event (roe_eventid)) |
||
130 | ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; |
||
131 | $GLOBALS['xoopsDB']->queryF($sql); |
||
132 | |||
133 | $sql = "CREATE TABLE IF NOT EXISTS {$GLOBALS['xoopsDB']->prefix('apcal_ro_members')} ( |
||
134 | rom_id int(10) unsigned NOT NULL AUTO_INCREMENT, |
||
135 | rom_eventid mediumint(8) unsigned zerofill NOT NULL DEFAULT '00000000', |
||
136 | rom_firstname varchar(200) DEFAULT NULL, |
||
137 | rom_lastname varchar(200) DEFAULT NULL, |
||
138 | rom_email varchar(200) DEFAULT NULL, |
||
139 | rom_extrainfo1 varchar(200) DEFAULT NULL, |
||
140 | rom_extrainfo2 varchar(200) DEFAULT NULL, |
||
141 | rom_extrainfo3 varchar(200) DEFAULT NULL, |
||
142 | rom_extrainfo4 varchar(200) DEFAULT NULL, |
||
143 | rom_extrainfo5 varchar(200) DEFAULT NULL, |
||
144 | rom_poster_ip varchar(200) DEFAULT NULL, |
||
145 | rom_status int(10) NOT NULL DEFAULT '0', |
||
146 | rom_submitter int(10) NOT NULL DEFAULT '0', |
||
147 | rom_date_created int(10) NOT NULL DEFAULT '0', |
||
148 | PRIMARY KEY (rom_id), |
||
149 | UNIQUE KEY UNQ_EMAIL (rom_eventid, rom_email), |
||
150 | KEY event (rom_eventid)) |
||
151 | ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; |
||
152 | $GLOBALS['xoopsDB']->queryF($sql); |
||
153 | |||
154 | $sql = "CREATE TABLE IF NOT EXISTS {$GLOBALS['xoopsDB']->prefix('apcal_ro_notify')} ( |
||
155 | ron_id int(10) unsigned NOT NULL AUTO_INCREMENT, |
||
156 | ron_eventid mediumint(8) unsigned zerofill NOT NULL DEFAULT '00000000', |
||
157 | ron_email varchar(200) DEFAULT NULL, |
||
158 | ron_submitter int(10) DEFAULT NULL, |
||
159 | ron_date_created int(11) NOT NULL DEFAULT '0', |
||
160 | PRIMARY KEY (ron_id), |
||
161 | KEY event (ron_eventid)) |
||
162 | ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; |
||
163 | $GLOBALS['xoopsDB']->queryF($sql); |
||
164 | |||
165 | $GLOBALS['xoopsDB']->queryF("UPDATE {$GLOBALS['xoopsDB']->prefix('apcal_event')} SET start_date=NULL,end_date=NULL"); |
||
166 | $GLOBALS['xoopsDB']->queryF("UPDATE {$GLOBALS['xoopsDB']->prefix('apcal_event')} t, (SELECT id, shortsummary FROM {$GLOBALS['xoopsDB']->prefix('apcal_event')} x WHERE x.rrule_pid>0 GROUP BY x.shortsummary ORDER BY start) AS e SET t.rrule_pid=e.id WHERE t.shortsummary=e.shortsummary;"); |
||
167 | |||
168 | // fix problem from removed poster_ip |
||
169 | $sql = "ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_ro_members')} ADD `rom_status` INT(1) NOT NULL DEFAULT '0' AFTER `rom_extrainfo5`;"; |
||
170 | $GLOBALS['xoopsDB']->queryF($sql); |
||
171 | // fix problem from removed poster_ip |
||
172 | $sql = "ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_ro_members')} ADD `rom_poster_ip` VARCHAR(200) NULL DEFAULT '' AFTER `rom_extrainfo5`;"; |
||
173 | $GLOBALS['xoopsDB']->queryF($sql); |
||
174 | |||
175 | // fix problem from removed roe_waitinglist |
||
176 | $sql = "ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_ro_events')} ADD `roe_waitinglist` INT(10) NOT NULL DEFAULT '0' AFTER `roe_datelimit`;"; |
||
177 | $GLOBALS['xoopsDB']->queryF($sql); |
||
178 | |||
179 | // fix problem from removed roe_waitinglist |
||
180 | $sql = "ALTER TABLE {$GLOBALS['xoopsDB']->prefix('apcal_ro_events')} ADD `roe_needconfirm` INT(10) NOT NULL DEFAULT '0' AFTER `roe_datelimit`;"; |
||
181 | $GLOBALS['xoopsDB']->queryF($sql); |
||
182 | |||
183 | // if (!is_dir(XOOPS_UPLOAD_PATH . '/apcal/')) { |
||
184 | // mkdir(XOOPS_UPLOAD_PATH . '/apcal/', 0755); |
||
185 | // } |
||
186 | // if (!is_dir(XOOPS_UPLOAD_PATH . '/apcal/thumbs/')) { |
||
187 | // mkdir(XOOPS_UPLOAD_PATH . '/apcal/thumbs/', 0755); |
||
188 | // } |
||
189 | |||
190 | require_once __DIR__ . '/config.php'; |
||
191 | $configurator = new ModuleConfigurator(); |
||
192 | $classUtility = ucfirst($moduleDirName) . 'Utility'; |
||
193 | if (!class_exists($classUtility)) { |
||
194 | xoops_load('utility', $moduleDirName); |
||
195 | } |
||
196 | |||
197 | //delete old HTML templates |
||
198 | if (count($configurator->templateFolders) > 0) { |
||
199 | foreach ($configurator->templateFolders as $folder) { |
||
200 | $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
||
201 | if (is_dir($templateFolder)) { |
||
202 | $templateList = array_diff(scandir($templateFolder), array('..', '.')); |
||
203 | foreach ($templateList as $k => $v) { |
||
204 | $fileInfo = new SplFileInfo($templateFolder . $v); |
||
205 | if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
||
206 | if (file_exists($templateFolder . $v)) { |
||
207 | unlink($templateFolder . $v); |
||
208 | } |
||
209 | } |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | // --- DELETE OLD FILES --------------- |
||
216 | if (count($configurator->oldFiles) > 0) { |
||
217 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
218 | foreach (array_keys($configurator->oldFiles) as $i) { |
||
219 | $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
||
220 | if (is_file($tempFile)) { |
||
221 | unlink($tempFile); |
||
222 | } |
||
223 | } |
||
224 | } |
||
225 | |||
226 | // --- DELETE OLD FOLDERS --------------- |
||
227 | xoops_load('XoopsFile'); |
||
228 | if (count($configurator->oldFolders) > 0) { |
||
229 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
230 | foreach (array_keys($configurator->oldFolders) as $i) { |
||
231 | $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
||
232 | /* @var $folderHandler XoopsObjectHandler */ |
||
233 | $folderHandler = XoopsFile::getHandler('folder', $tempFolder); |
||
234 | $folderHandler->delete($tempFolder); |
||
235 | } |
||
236 | } |
||
237 | |||
238 | // --- CREATE FOLDERS --------------- |
||
239 | View Code Duplication | if (count($configurator->uploadFolders) > 0) { |
|
240 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
241 | foreach (array_keys($configurator->uploadFolders) as $i) { |
||
242 | $classUtility::createFolder($configurator->uploadFolders[$i]); |
||
243 | } |
||
244 | } |
||
245 | |||
246 | // --- COPY blank.png FILES --------------- |
||
247 | View Code Duplication | if (count($configurator->blankFiles) > 0) { |
|
248 | $file = __DIR__ . '/../assets/images/blank.png'; |
||
249 | foreach (array_keys($configurator->blankFiles) as $i) { |
||
250 | $dest = $configurator->blankFiles[$i] . '/blank.png'; |
||
251 | $classUtility::copyFile($file, $dest); |
||
252 | } |
||
253 | } |
||
254 | |||
255 | //delete .html entries from the tpl table |
||
256 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\''; |
||
257 | $GLOBALS['xoopsDB']->queryF($sql); |
||
258 | |||
259 | /** @var XoopsGroupPermHandler $gpermHandler */ |
||
260 | $gpermHandler = xoops_getHandler('groupperm'); |
||
261 | |||
262 | return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
263 | |||
264 | return true; |
||
265 | } |
||
266 | |||
346 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.