GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 423fe8...f48289 )
by gyeong-won
15:56 queued 08:14
created

moduleModel::needUpdate()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 10
nop 1
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  moduleModel
5
 * @author NAVER ([email protected])
6
 * @brief Model class of module module
7
 */
8
class moduleModel extends module
9
{
10
	/**
11
	 * @brief Initialization
12
	 */
13
	function init()
14
	{
15
	}
16
17
	/**
18
	 * @brief Check if mid, vid are available
19
	 */
20
	function isIDExists($id, $site_srl = 0)
21
	{
22
		if(!preg_match('/^[a-z]{1}([a-z0-9_]+)$/i',$id)) return true;
23
		// directory and rss/atom/api reserved checking, etc.
24
		$dirs = FileHandler::readDir(_XE_PATH_);
25
		$dirs[] = 'rss';
26
		$dirs[] = 'atom';
27
		$dirs[] = 'api';
28
		if(in_array($id, $dirs)) return true;
29
		// mid test
30
		$args = new stdClass();
31
		$args->mid = $id;
32
		$args->site_srl = $site_srl;
33
		$output = executeQuery('module.isExistsModuleName', $args);
34
		if($output->data->count) return true;
35
		// vid test (check mid != vid if site_srl=0, which means it is not a virtual site)
36
		if(!$site_srl)
37
		{
38
			$site_args = new stdClass();
39
			$site_args->domain = $id;
40
			$output = executeQuery('module.isExistsSiteDomain', $site_args);
41
			if($output->data->count) return true;
42
		}
43
44
		return false;
45
	}
46
47
	/**
48
	 * @brief Get site information
49
	 */
50
	function getSiteInfo($site_srl, $columnList = array())
51
	{
52
		$args = new stdClass();
53
		$args->site_srl = $site_srl;
54
		$output = executeQuery('module.getSiteInfo', $args, $columnList);
55
		return $output->data;
56
	}
57
58
	function getSiteInfoByDomain($domain, $columnList = array())
59
	{
60
		$args = new stdClass();
61
		$args->domain = $domain;
62
		$output = executeQuery('module.getSiteInfoByDomain', $args, $columnList);
63
		return $output->data;
64
	}
65
66
	/**
67
	 * @brief Get module information with document_srl
68
	 * In this case, it is unable to use the cache file
69
	 */
70
	function getModuleInfoByDocumentSrl($document_srl)
71
	{
72
		$args = new stdClass();
73
		$args->document_srl = $document_srl;
74
		$output = executeQuery('module.getModuleInfoByDocument', $args);
75
		$this->applyDefaultSkin($output->data);
76
		return $this->addModuleExtraVars($output->data);
77
	}
78
79
	/**
80
	 * @brief Get the default mid according to the domain
81
	 */
82
	function getDefaultMid()
83
	{
84
		$default_url = Context::getDefaultUrl();
85 View Code Duplication
		if($default_url && substr_compare($default_url, '/', -1) === 0) $default_url = substr($default_url, 0, -1);
86
87
		$request_url = Context::getRequestUri();
88
		if($request_url && substr_compare($request_url, '/', -1) === 0) $request_url = substr($request_url, 0, -1);
89
90
		$default_url_parse = parse_url($default_url);
91
		$request_url_parse = parse_url($request_url);
92
		$vid = Context::get('vid');
93
		$mid = Context::get('mid');
94
95
		// Set up
96
		$domain = '';
97
		$site_info = NULL;
98
		if($default_url && $default_url_parse['host'] != $request_url_parse['host'])
99
		{
100
			$hostname = $request_url_parse['host'];
101
			$path = $request_url_parse['path'];
102
			$port = $request_url_parse['port'];
103 View Code Duplication
			if(strlen($path) >= 1 && substr_compare($path, '/', -1) === 0) $path = substr($path, 0, -1);
104
105
			$domain = sprintf('%s%s%s', $hostname, $port && ($port != 80 )? ':'.$port  : '', $path);
106
		}
107
108
		if($domain === '')
109
		{
110
			if(!$vid) $vid = $mid;
111
			if($vid)
112
			{
113
				$domain = $vid;
114
			}
115
		}
116
117
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
118
		// If domain is set, look for subsite
119
		if($domain !== '')
120
		{
121
			$site_info = false;
122
			if($oCacheHandler->isSupport())
123
			{
124
				$object_key = 'site_info:' . md5($domain);
125
				$domain_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
126
				$site_info = $oCacheHandler->get($domain_cache_key);
127
			}
128
129
			if($site_info === false)
130
			{
131
				$args = new stdClass();
132
				$args->domain = $domain;
133
				$output = executeQuery('module.getSiteInfoByDomain', $args);
134
				$site_info = $output->data;
135
136
				if($oCacheHandler->isSupport()) $oCacheHandler->put($domain_cache_key, $site_info);
0 ignored issues
show
Bug introduced by
The variable $domain_cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
137
			}
138
139
			if($site_info && $vid)
140
			{
141
				Context::set('vid', $site_info->domain, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
				if(strtolower($mid)==strtolower($site_info->domain)) Context::set('mid', $site_info->mid,true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
143
			}
144
			if(!$site_info || !$site_info->domain) { $domain = ''; unset($site_info); }
145
		}
146
147
		// If no virtual website was found, get default website
148
		if($domain === '')
149
		{
150
			$site_info = false;
151
			if($oCacheHandler->isSupport())
152
			{
153
				$object_key = 'default_site';
154
				$default_site_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
155
				$site_info = $oCacheHandler->get($default_site_cache_key);
156
			}
157
158
			if($site_info === false)
159
			{
160
				$args = new stdClass();
161
				$args->site_srl = 0;
162
				$output = executeQuery('module.getSiteInfo', $args);
163
				// Update the related informaion if there is no default site info
164
				if(!$output->data)
165
				{
166
					// Create a table if sites table doesn't exist
167
					$oDB = &DB::getInstance();
168
					if(!$oDB->isTableExists('sites')) $oDB->createTableByXmlFile(_XE_PATH_.'modules/module/schemas/sites.xml');
0 ignored issues
show
Bug introduced by
The method createTableByXmlFile() does not exist on DB. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
169
					if(!$oDB->isTableExists('sites')) return;
170
171
					// Get mid, language
172
					$mid_output = $oDB->executeQuery('module.getDefaultMidInfo', $args);
173
					$db_info = Context::getDBInfo();
174
					$domain = Context::getDefaultUrl();
175
					$url_info = parse_url($domain);
176
					$domain = $url_info['host'].( (!empty($url_info['port'])&&$url_info['port']!=80)?':'.$url_info['port']:'').$url_info['path'];
177
178
					$site_args = new stdClass;
179
					$site_args->site_srl = 0;
180
					$site_args->index_module_srl  = $mid_output->data->module_srl;
181
					$site_args->domain = $domain;
182
					$site_args->default_language = $db_info->lang_type;
183
184
					if($output->data && !$output->data->index_module_srl)
185
					{
186
						$output = executeQuery('module.updateSite', $site_args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
187
					}
188
					else
189
					{
190
						$output = executeQuery('module.insertSite', $site_args);
191
						if(!$output->toBool()) return $output;
192
					}
193
					$output = executeQuery('module.getSiteInfo', $args);
194
				}
195
				$site_info = $output->data;
196
				if($oCacheHandler->isSupport()) $oCacheHandler->put($default_site_cache_key, $site_info);
0 ignored issues
show
Bug introduced by
The variable $default_site_cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
197
			}
198
		}
199
200
		if(!$site_info->module_srl) return $site_info;
201
		if(is_array($site_info) && $site_info->data[0]) $site_info = $site_info[0];
202
		return $this->addModuleExtraVars($site_info);
203
	}
204
205
	/**
206
	 * @brief Get module information by mid
207
	 */
208
	function getModuleInfoByMid($mid, $site_srl = 0, $columnList = array())
0 ignored issues
show
Unused Code introduced by
The parameter $columnList is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
209
	{
210
		if(!$mid || ($mid && !preg_match("/^[a-z][a-z0-9_]+$/i", $mid)))
211
		{
212
			return;
213
		}
214
215
		$args = new stdClass();
216
		$args->mid = $mid;
217
		$args->site_srl = (int)$site_srl;
218
219
		$module_srl = false;
0 ignored issues
show
Unused Code introduced by
$module_srl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
220
		$module_info = false;
221
222
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
223
		if($oCacheHandler->isSupport())
224
		{
225
			$object_key = 'module_srl:'.$mid.'_'.$site_srl;
226
			$module_srl_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
227
			$module_srl = $oCacheHandler->get($module_srl_cache_key);
228 View Code Duplication
			if($module_srl)
229
			{
230
				$object_key = 'mid_info:' . $module_srl;
231
				$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
232
				$module_info = $oCacheHandler->get($module_info_cache_key);
233
			}
234
		}
235
236
		if($module_info === false)
237
		{
238
			$output = executeQuery('module.getMidInfo', $args);
239
			$module_info = $output->data;
240
			if($oCacheHandler->isSupport())
241
			{
242
				$oCacheHandler->put($module_srl_cache_key, $module_info->module_srl);
0 ignored issues
show
Bug introduced by
The variable $module_srl_cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
243
244
				$object_key = 'mid_info:' . $module_info->module_srl;
245
				$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
246
				$oCacheHandler->put($module_info_cache_key, $module_info);
247
			}
248
		}
249
250
		$this->applyDefaultSkin($module_info);
251
		if(!$module_info->module_srl && $module_info->data[0]) $module_info = $module_info->data[0];
252
		return $this->addModuleExtraVars($module_info);
253
	}
254
255
	/**
256
	 * Get module info by menu_item_srl.
257
	 *
258
	 * @params int $menu_item_srl
259
	 *
260
	 * @return Object $moduleInfo
261
	 */
262
	public function getModuleInfoByMenuItemSrl($menu_item_srl = 0)
263
	{
264
		$menuItemSrl = Context::get('menu_item_srl');
265
		$menuItemSrl = (!$menuItemSrl) ? $menu_item_srl : $menuItemSrl;
266
267
		if(!$menuItemSrl)
268
		{
269
			$this->stop(-1, 'msg_invalid_request');
0 ignored issues
show
Unused Code introduced by
The call to moduleModel::stop() has too many arguments starting with 'msg_invalid_request'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
270
			return;
271
		}
272
273
		$args = new stdClass();
274
		$args->menu_item_srl = $menuItemSrl;
275
		$output = executeQuery('module.getModuleInfoByMenuItemSrl', $args);
276
		if(!$output->toBool())
277
		{
278
			return $output;
279
		}
280
281
		$moduleInfo = $output->data;
282
		$mid = $moduleInfo->mid;
283
		$site_srl = $moduleInfo->site_srl;
284
285
		$moduleInfo->designSettings = new stdClass();
286
		$moduleInfo->designSettings->layout = new stdClass();
287
		$moduleInfo->designSettings->skin = new stdClass();
288
289
		$oLayoutAdminModel = getAdminModel('layout');
290
		$layoutSrlPc = ($moduleInfo->layout_srl == -1) ? $oLayoutAdminModel->getSiteDefaultLayout('P', $moduleInfo->site_srl) : $moduleInfo->layout_srl;
291
		$layoutSrlMobile = ($moduleInfo->mlayout_srl == -1) ? $oLayoutAdminModel->getSiteDefaultLayout('M', $moduleInfo->site_srl) : $moduleInfo->mlayout_srl;
292
		$skinNamePc = ($moduleInfo->is_skin_fix == 'N') ? $this->getModuleDefaultSkin($moduleInfo->module, 'P') : $moduleInfo->skin;
293
		$skinNameMobile = ($moduleInfo->is_mskin_fix == 'N') ? $this->getModuleDefaultSkin($moduleInfo->module, 'M') : $moduleInfo->mskin;
294
295
		$oLayoutModel = getModel('layout');
296
		$layoutInfoPc = $layoutSrlPc ? $oLayoutModel->getLayoutRawData($layoutSrlPc, array('title')) : NULL;
297
		$layoutInfoMobile = $layoutSrlMobile ? $oLayoutModel->getLayoutRawData($layoutSrlMobile, array('title')) : NULL;
298
		$skinInfoPc = $this->loadSkinInfo(Modulehandler::getModulePath($moduleInfo->module), $skinNamePc);
299
		$skinInfoMobile = $this->loadSkinInfo(Modulehandler::getModulePath($moduleInfo->module), $skinNameMobile, 'm.skins');
300
		if(!$skinInfoPc)
301
		{
302
			$skinInfoPc = new stdClass();
303
			$skinInfoPc->title = $skinNamePc;
304
		}
305
		if(!$skinInfoMobile)
306
		{
307
			$skinInfoMobile = new stdClass();
308
			$skinInfoMobile->title = $skinNameMobile;
309
		}
310
311
		$moduleInfo->designSettings->layout->pcIsDefault = $moduleInfo->layout_srl == -1 ? 1 : 0;
312
		$moduleInfo->designSettings->layout->pc = $layoutInfoPc->title;
313
		$moduleInfo->designSettings->layout->mobileIsDefault = $moduleInfo->mlayout_srl == -1 ? 1 : 0;
314
		$moduleInfo->designSettings->layout->mobile = $layoutInfoMobile->title;
315
		$moduleInfo->designSettings->skin->pcIsDefault = $moduleInfo->is_skin_fix == 'N' ? 1 : 0;
316
		$moduleInfo->designSettings->skin->pc = $skinInfoPc->title;
317
		$moduleInfo->designSettings->skin->mobileIsDefault = $moduleInfo->is_mskin_fix == 'N' ? 1 : 0;
318
		$moduleInfo->designSettings->skin->mobile = $skinInfoMobile->title;
319
320
		$module_srl = false;
0 ignored issues
show
Unused Code introduced by
$module_srl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
321
		$mid_info = false;
322
323
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
324
		if($oCacheHandler->isSupport())
325
		{
326
			$object_key = 'module_srl:'.$mid.'_'.$site_srl;
327
			$module_srl_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
328
			$module_srl = $oCacheHandler->get($module_srl_cache_key);
329 View Code Duplication
			if($module_srl)
330
			{
331
				$object_key = 'mid_info:' . $module_srl;
332
				$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
333
				$mid_info = $oCacheHandler->get($module_info_cache_key);
334
			}
335
336
			if($mid_info === false)
337
			{
338
				$oCacheHandler->put($module_srl_cache_key, $output->data->module_srl);
339
340
				$object_key = 'mid_info:' . $output->data->module_srl;
341
				$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
342
				$oCacheHandler->put($module_info_cache_key, $moduleInfo);
343
			}
344
			else
345
			{
346
				$mid_info->designSettings = $moduleInfo->designSettings;
347
				$moduleInfo = $mid_info;
348
			}
349
		}
350
351
		$moduleInfo = $this->addModuleExtraVars($moduleInfo);
352
353
		if($moduleInfo->module == 'page' && $moduleInfo->page_type != 'ARTICLE')
354
		{
355
			unset($moduleInfo->skin);
356
			unset($moduleInfo->mskin);
357
		}
358
359
		$this->add('module_info_by_menu_item_srl', $moduleInfo);
360
361
		return $moduleInfo;
362
	}
363
364
	/**
365
	 * @brief Get module information corresponding to module_srl
366
	 */
367
	function getModuleInfoByModuleSrl($module_srl, $columnList = array())
368
	{
369
		$mid_info = false;
370
371
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
372
		if($oCacheHandler->isSupport())
373
		{
374
			$object_key = 'mid_info:' . $module_srl;
375
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
376
			$mid_info = $oCacheHandler->get($cache_key);
377
		}
378
379 View Code Duplication
		if($mid_info === false)
380
		{
381
			// Get data
382
			$args = new stdClass();
383
			$args->module_srl = $module_srl;
384
			$output = executeQuery('module.getMidInfo', $args);
385
			if(!$output->toBool()) return;
386
387
			$mid_info = $output->data;
388
			$this->applyDefaultSkin($mid_info);
389
			if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $mid_info);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
390
		}
391
392
		if($mid_info && count($columnList))
393
		{
394
			$module_info = new stdClass();
395
			foreach($mid_info as $key => $item)
0 ignored issues
show
Bug introduced by
The expression $mid_info of type object<stdClass>|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
396
			{
397
				if(in_array($key, $columnList))
398
				{
399
					$module_info->$key = $item;
400
				}
401
			}
402
		}
403
		else $module_info = $mid_info;
404
405
		$oModuleController = getController('module');
406
		if(isset($module_info->browser_title)) $oModuleController->replaceDefinedLangCode($module_info->browser_title);
407
408
		$this->applyDefaultSkin($module_info);
0 ignored issues
show
Bug introduced by
It seems like $module_info defined by $mid_info on line 403 can also be of type boolean; however, moduleModel::applyDefaultSkin() does only seem to accept object<stdClass>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
409
		return $this->addModuleExtraVars($module_info);
410
	}
411
412
	/**
413
	 * Apply default skin info
414
	 *
415
	 * @param stdClass $moduleInfo Module information
416
	 */
417
	private function applyDefaultSkin(&$moduleInfo)
418
	{
419
		if($moduleInfo->is_skin_fix == 'N')
420
		{
421
			$moduleInfo->skin = '/USE_DEFAULT/';
422
		}
423
424
		if($moduleInfo->is_mskin_fix == 'N')
425
		{
426
			$moduleInfo->mskin = '/USE_DEFAULT/';
427
		}
428
	}
429
	/**
430
	 * @brief Get module information corresponding to layout_srl
431
	 */
432
	function getModulesInfoByLayout($layout_srl, $columnList = array())
433
	{
434
		// Imported data
435
		$args = new stdClass;
436
		$args->layout_srl = $layout_srl;
437
		$output = executeQueryArray('module.getModulesByLayout', $args, $columnList);
438
439
		$count = count($output->data);
440
441
		$modules = array();
442 View Code Duplication
		for($i=0;$i<$count;$i++)
443
		{
444
			$modules[] = $output->data[$i];
445
		}
446
		return $this->addModuleExtraVars($modules);
447
	}
448
449
	/**
450
	 * @brief Get module information corresponding to multiple module_srls
451
	 */
452
	function getModulesInfo($module_srls, $columnList = array())
453
	{
454
		if(is_array($module_srls)) $module_srls = implode(',',$module_srls);
455
		$args = new stdClass();
456
		$args->module_srls = $module_srls;
457
		$output = executeQueryArray('module.getModulesInfo', $args, $columnList);
458
		if(!$output->toBool()) return;
459
		return $this->addModuleExtraVars($output->data);
460
	}
461
462
	/**
463
	 * @brief Add extra vars to the module basic information
464
	 */
465
	function addModuleExtraVars($module_info)
466
	{
467
		// Process although one or more module informaion is requested
468
		if(!is_array($module_info)) $target_module_info = array($module_info);
469
		else $target_module_info = $module_info;
470
		// Get module_srl
471
		$module_srls = array();
472
		foreach($target_module_info as $key => $val)
473
		{
474
			$module_srl = $val->module_srl;
475
			if(!$module_srl) continue;
476
			$module_srls[] = $val->module_srl;
477
		}
478
		// Extract extra information of the module and skin
479
		$extra_vars = $this->getModuleExtraVars($module_srls);
480
		if(!count($module_srls) || !count($extra_vars)) return $module_info;
481
482
		foreach($target_module_info as $key => $val)
483
		{
484
			if(!$extra_vars[$val->module_srl] || !count($extra_vars[$val->module_srl])) continue;
485
			foreach($extra_vars[$val->module_srl] as $k => $v)
486
			{
487
				if($target_module_info[$key]->{$k}) continue;
488
				$target_module_info[$key]->{$k} = $v;
489
			}
490
		}
491
492
		if(is_array($module_info)) return $target_module_info;
493
		return $target_module_info[0];
494
	}
495
496
	/**
497
	 * @brief Get a complete list of mid, which is created in the DB
498
	 */
499
	function getMidList($args = null, $columnList = array())
500
	{
501
		$list = false;
502
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
503
		if($oCacheHandler->isSupport())
504
		{
505
			if(count($args) === 1 && isset($args->site_srl))
506
			{
507
				$object_key = 'module:mid_list_' . $args->site_srl;
508
				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
509
				$list = $oCacheHandler->get($cache_key);
510
			}
511
		}
512
513
		if($list === false)
514
		{
515 View Code Duplication
			if($oCacheHandler->isSupport() && count($args) === 1 && isset($args->site_srl))
516
			{
517
				$columnList = array();
518
			}
519
520
			$output = executeQuery('module.getMidList', $args, $columnList);
521
			if(!$output->toBool()) return $output;
522
			$list = $output->data;
523
524 View Code Duplication
			if($oCacheHandler->isSupport() && count($args) === 1 && isset($args->site_srl))
525
			{
526
				$oCacheHandler->put($cache_key, $list);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
527
			}
528
		}
529
		if(!$list) return;
530
531
		if(!is_array($list)) $list = array($list);
532
533
		foreach($list as $val)
534
		{
535
			$mid_list[$val->mid] = $val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$mid_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $mid_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
536
		}
537
538
		return $mid_list;
0 ignored issues
show
Bug introduced by
The variable $mid_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
539
	}
540
541
	/**
542
	 * @brief Get a complete list of module_srl, which is created in the DB
543
	 */
544
	function getModuleSrlList($args = null, $columnList = array())
545
	{
546
		$output = executeQueryArray('module.getMidList', $args, $columnList);
547
		if(!$output->toBool()) return $output;
548
549
		$list = $output->data;
550
		if(!$list) return;
551
552
		return $list;
553
	}
554
555
	/**
556
	 * @brief Return an array of module_srl corresponding to a mid list
557
	 */
558
	function getModuleSrlByMid($mid)
559
	{
560
		if($mid && !is_array($mid)) $mid = explode(',',$mid);
561
		if(is_array($mid)) $mid = "'".implode("','",$mid)."'";
562
563
		$site_module_info = Context::get('site_module_info');
564
565
		$args = new stdClass;
566
		$args->mid = $mid;
567
		if($site_module_info) $args->site_srl = $site_module_info->site_srl;
568
		$output = executeQuery('module.getModuleSrlByMid', $args);
569
		if(!$output->toBool()) return $output;
570
571
		$list = $output->data;
572
		if(!$list) return;
573
		if(!is_array($list)) $list = array($list);
574
575
		foreach($list as $key => $val)
576
		{
577
			$module_srl_list[] = $val->module_srl;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$module_srl_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $module_srl_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
578
		}
579
580
		return $module_srl_list;
0 ignored issues
show
Bug introduced by
The variable $module_srl_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
581
	}
582
583
	/**
584
	 * @brief Get forward value by the value of act
585
	 */
586
	function getActionForward($act)
587
	{
588
		$action_forward = false;
589
		// cache controll
590
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
591
		if($oCacheHandler->isSupport())
592
		{
593
			$cache_key = 'action_forward';
594
			$action_forward = $oCacheHandler->get($cache_key);
595
		}
596
597
		// retrieve and caching all registered action_forward
598
		if($action_forward === false)
599
		{
600
			$args = new stdClass();
601
			$output = executeQueryArray('module.getActionForward',$args);
602
			if(!$output->toBool()) return new stdClass;
603
			if(!$output->data) $output->data = array();
604
605
			$action_forward = array();
606
			foreach($output->data as $item)
607
			{
608
				$action_forward[$item->act] = $item;
609
			}
610
611
			if($oCacheHandler->isSupport())
612
			{
613
				$oCacheHandler->put($cache_key, $action_forward);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
614
			}
615
		}
616
617
		if($action_forward[$act])
618
		{
619
			return $action_forward[$act];
620
		}
621
		else
622
		{
623
			return new stdClass();
624
		}
625
	}
626
627
	/**
628
	 * @brief Get a list of all triggers on the trigger_name
629
	 */
630
	function getTriggers($trigger_name, $called_position)
631
	{
632
		if(is_null($GLOBALS['__triggers__']))
633
		{
634
			$triggers = FALSE;
635
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
636
			if($oCacheHandler->isSupport())
637
			{
638
				$cache_key = 'triggers';
639
				$triggers = $oCacheHandler->get($cache_key);
640
			}
641
			if($triggers === FALSE)
642
			{
643
				$output = executeQueryArray('module.getTriggers');
644
				$triggers = $output->data;
645
				if($output->toBool() && $oCacheHandler->isSupport())
646
				{
647
					$oCacheHandler->put($cache_key, $triggers);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
648
				}
649
			}
650
			foreach($triggers as $item)
651
			{
652
				$GLOBALS['__triggers__'][$item->trigger_name][$item->called_position][] = $item;
653
			}
654
		}
655
656
		return $GLOBALS['__triggers__'][$trigger_name][$called_position];
657
	}
658
659
	/**
660
	 * @brief Get specific triggers from the trigger_name
661
	 */
662
	function getTrigger($trigger_name, $module, $type, $called_method, $called_position)
663
	{
664
		$triggers = $this->getTriggers($trigger_name, $called_position);
665
666
		if($triggers && is_array($triggers))
667
		{
668
			foreach($triggers as $item)
669
			{
670
				if($item->module == $module && $item->type == $type && $item->called_method == $called_method)
671
				{
672
					return $item;
673
				}
674
			}
675
		}
676
677
		return NULL;
678
	}
679
680
	/**
681
	 * @brief Get module extend
682
	 */
683
	function getModuleExtend($parent_module, $type, $kind='')
684
	{
685
		$key = $parent_module.'.'.$kind.'.'.$type;
686
687
		$module_extend_info = $this->loadModuleExtends();
688
		if(array_key_exists($key, $module_extend_info))
689
		{
690
			return $module_extend_info[$key];
691
		}
692
693
		return false;
694
	}
695
696
	/**
697
	 * @brief Get all the module extend
698
	 */
699
	function loadModuleExtends()
700
	{
701
		$cache_file = './files/config/module_extend.php';
702
		$cache_file = FileHandler::getRealPath($cache_file);
703
704
		if(!isset($GLOBALS['__MODULE_EXTEND__']))
705
		{
706
			// check pre install
707
			if(file_exists(FileHandler::getRealPath('./files')) && !file_exists($cache_file))
708
			{
709
				$arr = array();
710
				$output = executeQueryArray('module.getModuleExtend');
711
				if($output->data)
712
				{
713
					foreach($output->data as $v)
714
					{
715
						$arr[] = sprintf("'%s.%s.%s' => '%s'", $v->parent_module, $v->kind, $v->type, $v->extend_module);
716
					}
717
				}
718
719
				$str = '<?PHP return array(%s); ?>';
720
				$str = sprintf($str, join(',',$arr));
721
722
				FileHandler::writeFile($cache_file, $str);
723
			}
724
725
726
			if(file_exists($cache_file))
727
			{
728
				$GLOBALS['__MODULE_EXTEND__'] = include($cache_file);
729
			}
730
			else
731
			{
732
				$GLOBALS['__MODULE_EXTEND__'] = array();
733
			}
734
		}
735
736
		return $GLOBALS['__MODULE_EXTEND__'];
737
	}
738
739
	/**
740
	 * @brief Get information from conf/info.xml
741
	 */
742
	function getModuleInfoXml($module)
743
	{
744
		// Get a path of the requested module. Return if not exists.
745
		$module_path = ModuleHandler::getModulePath($module);
746
		if(!$module_path) return;
747
		// Read the xml file for module skin information
748
		$xml_file = sprintf("%s/conf/info.xml", $module_path);
749
		if(!file_exists($xml_file)) return;
750
751
		$oXmlParser = new XmlParser();
752
		$tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
753
		$xml_obj = $tmp_xml_obj->module;
754
755
		if(!$xml_obj) return;
756
757
		// Module Information
758
		$module_info = new stdClass();
759
		if($xml_obj->version && $xml_obj->attrs->version == '0.2')
760
		{
761
			// module format 0.2
762
			$module_info->title = $xml_obj->title->body;
763
			$module_info->description = $xml_obj->description->body;
764
			$module_info->version = $xml_obj->version->body;
765
			$module_info->homepage = $xml_obj->link->body;
766
			$module_info->category = $xml_obj->category->body;
767
			if(!$module_info->category) $module_info->category = 'service';
768
			sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
0 ignored issues
show
Bug introduced by
The variable $date_obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
769
			$module_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
770
			$module_info->license = $xml_obj->license->body;
771
			$module_info->license_link = $xml_obj->license->attrs->link;
772
773 View Code Duplication
			if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$author_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $author_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
774
			else $author_list = $xml_obj->author;
775
776 View Code Duplication
			foreach($author_list as $author)
777
			{
778
				$author_obj = new stdClass();
779
				$author_obj->name = $author->name->body;
780
				$author_obj->email_address = $author->attrs->email_address;
781
				$author_obj->homepage = $author->attrs->link;
782
				$module_info->author[] = $author_obj;
783
			}
784
		}
785
		else
786
		{
787
			// module format 0.1
788
			$module_info->title = $xml_obj->title->body;
789
			$module_info->description = $xml_obj->author->description->body;
790
			$module_info->version = $xml_obj->attrs->version;
791
			$module_info->category = $xml_obj->attrs->category;
792
			if(!$module_info->category) $module_info->category = 'service';
793
			sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
794
			$module_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
795
			$author_obj = new stdClass();
796
			$author_obj->name = $xml_obj->author->name->body;
797
			$author_obj->email_address = $xml_obj->author->attrs->email_address;
798
			$author_obj->homepage = $xml_obj->author->attrs->link;
799
			$module_info->author[] = $author_obj;
800
		}
801
		// Add admin_index by using action information
802
		$action_info = $this->getModuleActionXml($module);
803
		$module_info->admin_index_act = $action_info->admin_index_act;
804
		$module_info->default_index_act = $action_info->default_index_act;
805
		$module_info->setup_index_act = $action_info->setup_index_act;
806
		$module_info->simple_setup_index_act = $action_info->simple_setup_index_act;
807
808
		return $module_info;
809
	}
810
811
	/**
812
	 * @brief Return permisson and action data by conf/module.xml in the module
813
	 * Cache it because it takes too long to parse module.xml file
814
	 * When caching, add codes so to include it directly
815
	 * This is apparently good for performance, but not sure about its side-effects
816
	 */
817
	function getModuleActionXml($module)
818
	{
819
		// Get a path of the requested module. Return if not exists.
820
		$class_path = ModuleHandler::getModulePath($module);
821
		if(!$class_path) return;
822
823
		// Check if module.xml exists in the path. Return if not exist
824
		$xml_file = sprintf("%sconf/module.xml", $class_path);
825
		if(!file_exists($xml_file)) return;
826
827
		// Check if cached file exists
828
		$cache_file = sprintf(_XE_PATH_ . "files/cache/module_info/%s.%s.%s.php", $module, Context::getLangType(), __XE_VERSION__);
829
830
		// Update if no cache file exists or it is older than xml file
831
		if(!file_exists($cache_file) || filemtime($cache_file) < filemtime($xml_file) || $re_cache)
0 ignored issues
show
Bug introduced by
The variable $re_cache does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
832
		{
833
			$info = new stdClass();
834
			$buff = array(); // /< Set buff variable to use in the cache file
835
			$buff[] = '<?php if(!defined("__XE__")) exit();';
836
			$buff[] = '$info = new stdClass;';
837
			$buff['default_index_act'] = '$info->default_index_act = \'%s\';';
838
			$buff['setup_index_act'] = '$info->setup_index_act=\'%s\';';
839
			$buff['simple_setup_index_act'] = '$info->simple_setup_index_act=\'%s\';';
840
			$buff['admin_index_act'] = '$info->admin_index_act = \'%s\';';
841
842
			$xml_obj = XmlParser::loadXmlFile($xml_file); // /< Read xml file and convert it to xml object
843
844
			if(!count($xml_obj->module)) return; // /< Error occurs if module tag doesn't included in the xml
845
846
			$grants = $xml_obj->module->grants->grant; // /< Permission information
847
			$permissions = $xml_obj->module->permissions->permission; // /<  Acting permission
848
			$menus = $xml_obj->module->menus->menu;
849
			$actions = $xml_obj->module->actions->action; // /< Action list (required)
850
851
			$default_index = $admin_index = '';
0 ignored issues
show
Unused Code introduced by
$admin_index is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$default_index is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
852
853
			// Arrange permission information
854
			if($grants)
855
			{
856
				if(is_array($grants)) $grant_list = $grants;
857
				else $grant_list[] = $grants;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$grant_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $grant_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
858
859
				$info->grant = new stdClass();
860
				$buff[] = '$info->grant = new stdClass;';
861
				foreach($grant_list as $grant)
862
				{
863
					$name = $grant->attrs->name;
864
					$default = $grant->attrs->default?$grant->attrs->default:'guest';
865
					$title = $grant->title->body;
866
867
					$info->grant->{$name} = new stdClass();
868
					$info->grant->{$name}->title = $title;
869
					$info->grant->{$name}->default = $default;
870
871
					$buff[] = sprintf('$info->grant->%s = new stdClass;', $name);
872
					$buff[] = sprintf('$info->grant->%s->title=\'%s\';', $name, $title);
873
					$buff[] = sprintf('$info->grant->%s->default=\'%s\';', $name, $default);
874
				}
875
			}
876
			// Permissions to grant
877
			if($permissions)
878
			{
879
				if(is_array($permissions)) $permission_list = $permissions;
880
				else $permission_list[] = $permissions;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$permission_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $permission_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
881
882
				$buff[] = '$info->permission = new stdClass;';
883
884
				$info->permission = new stdClass();
885
				foreach($permission_list as $permission)
886
				{
887
					$action = $permission->attrs->action;
888
					$target = $permission->attrs->target;
889
890
					$info->permission->{$action} = $target;
891
892
					$buff[] = sprintf('$info->permission->%s = \'%s\';', $action, $target);
893
				}
894
			}
895
			// for admin menus
896
			if($menus)
897
			{
898
				if(is_array($menus)) $menu_list = $menus;
899
				else $menu_list[] = $menus;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$menu_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menu_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
900
901
				$buff[] = '$info->menu = new stdClass;';
902
				$info->menu = new stdClass();
903
				foreach($menu_list as $menu)
904
				{
905
					$menu_name = $menu->attrs->name;
906
					$menu_title = is_array($menu->title) ? $menu->title[0]->body : $menu->title->body;
907
					$menu_type = $menu->attrs->type;
908
909
					$info->menu->{$menu_name} = new stdClass();
910
					$info->menu->{$menu_name}->title = $menu_title;
911
					$info->menu->{$menu_name}->acts = array();
912
					$info->menu->{$menu_name}->type = $menu_type;
913
914
					$buff[] = sprintf('$info->menu->%s = new stdClass;', $menu_name);
915
					$buff[] = sprintf('$info->menu->%s->title=\'%s\';', $menu_name, $menu_title);
916
					$buff[] = sprintf('$info->menu->%s->type=\'%s\';', $menu_name, $menu_type);
917
				}
918
			}
919
920
			// actions
921
			if($actions)
922
			{
923
				if(is_array($actions)) $action_list = $actions;
924
				else $action_list[] = $actions;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$action_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $action_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
925
926
				$buff[] = '$info->action = new stdClass;';
927
				$info->action = new stdClass();
928
				foreach($action_list as $action)
929
				{
930
					$name = $action->attrs->name;
931
932
					$type = $action->attrs->type;
933
					$grant = $action->attrs->grant?$action->attrs->grant:'guest';
934
					$standalone = $action->attrs->standalone=='false'?'false':'true';
935
					$ruleset = $action->attrs->ruleset?$action->attrs->ruleset:'';
936
					$method = $action->attrs->method?$action->attrs->method:'';
937
					$check_csrf = $action->attrs->check_csrf=='false'?'false':'true';
938
939
					$index = $action->attrs->index;
940
					$admin_index = $action->attrs->admin_index;
941
					$setup_index = $action->attrs->setup_index;
942
					$simple_setup_index = $action->attrs->simple_setup_index;
943
					$menu_index = $action->attrs->menu_index;
944
945
					$info->action->{$name} = new stdClass();
946
					$info->action->{$name}->type = $type;
947
					$info->action->{$name}->grant = $grant;
948
					$info->action->{$name}->standalone = $standalone;
949
					$info->action->{$name}->ruleset = $ruleset;
950
					$info->action->{$name}->method = $method;
951
					$info->action->{$name}->check_csrf = $check_csrf;
952
					if($action->attrs->menu_name)
953
					{
954
						if($menu_index == 'true')
955
						{
956
							$info->menu->{$action->attrs->menu_name}->index = $name;
957
							$buff[] = sprintf('$info->menu->%s->index=\'%s\';', $action->attrs->menu_name, $name);
958
						}
959
						if(is_array($info->menu->{$action->attrs->menu_name}->acts))
960
						{
961
							$info->menu->{$action->attrs->menu_name}->acts[] = $name;
962
							$currentKey = array_search($name, $info->menu->{$action->attrs->menu_name}->acts);
963
						}
964
965
						$buff[] = sprintf('$info->menu->%s->acts[%d]=\'%s\';', $action->attrs->menu_name, $currentKey, $name);
0 ignored issues
show
Bug introduced by
The variable $currentKey does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
966
						$i++;
0 ignored issues
show
Bug introduced by
The variable $i does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
967
					}
968
969
					$buff[] = sprintf('$info->action->%s = new stdClass;', $name);
970
					$buff[] = sprintf('$info->action->%s->type=\'%s\';', $name, $type);
971
					$buff[] = sprintf('$info->action->%s->grant=\'%s\';', $name, $grant);
972
					$buff[] = sprintf('$info->action->%s->standalone=\'%s\';', $name, $standalone);
973
					$buff[] = sprintf('$info->action->%s->ruleset=\'%s\';', $name, $ruleset);
974
					$buff[] = sprintf('$info->action->%s->method=\'%s\';', $name, $method);
975
					$buff[] = sprintf('$info->action->%s->check_csrf=\'%s\';', $name, $check_csrf);
976
977
					if($index=='true')
978
					{
979
						$default_index_act = $name;
980
						$info->default_index_act = $name;
981
					}
982
					if($admin_index=='true')
983
					{
984
						$admin_index_act = $name;
985
						$info->admin_index_act = $name;
986
					}
987
					if($setup_index=='true')
988
					{
989
						$setup_index_act = $name;
990
						$info->setup_index_act = $name;
991
					}
992
					if($simple_setup_index=='true')
993
					{
994
						$simple_setup_index_act = $name;
995
						$info->simple_setup_index_act = $name;
996
					}
997
				}
998
			}
999
			$buff['default_index_act'] = sprintf($buff['default_index_act'], $default_index_act);
0 ignored issues
show
Bug introduced by
The variable $default_index_act does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1000
			$buff['setup_index_act'] = sprintf($buff['setup_index_act'], $setup_index_act);
0 ignored issues
show
Bug introduced by
The variable $setup_index_act does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1001
			$buff['simple_setup_index_act'] = sprintf($buff['simple_setup_index_act'], $simple_setup_index_act);
0 ignored issues
show
Bug introduced by
The variable $simple_setup_index_act does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1002
			$buff['admin_index_act'] = sprintf($buff['admin_index_act'], $admin_index_act);
0 ignored issues
show
Bug introduced by
The variable $admin_index_act does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1003
1004
			$buff[] = 'return $info;';
1005
1006
			$buff = implode(PHP_EOL, $buff);
1007
1008
			FileHandler::writeFile($cache_file, $buff);
1009
1010
			return $info;
1011
		}
1012
1013
		if(file_exists($cache_file)) return include($cache_file);
1014
	}
1015
1016
	/**
1017
	 * Get a skin list for js API.
1018
	 * return void
1019
	 */
1020
	public function getModuleSkinInfoList()
1021
	{
1022
		$module = Context::get('module_type');
1023
1024
		if($module == 'ARTICLE')
1025
		{
1026
			$module = 'page';
1027
		}
1028
1029
		$skinType = Context::get('skin_type');
1030
1031
		$path = ModuleHandler::getModulePath($module);
1032
		$dir = ($skinType == 'M') ? 'm.skins' : 'skins';
1033
		$skin_list = $this->getSkins($path, $dir);
1034
1035
		$this->add('skin_info_list', $skin_list);
1036
	}
1037
1038
	/**
1039
	 * @brief Get a list of skins for the module
1040
	 * Return file analysis of skin and skin.xml
1041
	 */
1042
	function getSkins($path, $dir = 'skins')
1043
	{
1044
		if(substr($path, -1) == '/')
1045
		{
1046
			$path = substr($path, 0, -1);
1047
		}
1048
1049
		$skin_path = sprintf("%s/%s/", $path, $dir);
1050
		$list = FileHandler::readDir($skin_path);
1051
		if(!count($list)) return;
1052
1053
		natcasesort($list);
1054
1055
		foreach($list as $skin_name)
1056
		{
1057
			if(!is_dir($skin_path . $skin_name))
1058
			{
1059
				continue;
1060
			}
1061
			unset($skin_info);
1062
			$skin_info = $this->loadSkinInfo($path, $skin_name, $dir);
1063
			if(!$skin_info)
1064
			{
1065
				$skin_info = new stdClass();
1066
				$skin_info->title = $skin_name;
1067
			}
1068
1069
			$skin_list[$skin_name] = $skin_info;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$skin_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $skin_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1070
		}
1071
1072
		$tmpPath = strtr($path, array('/' => ' '));
1073
		$tmpPath = trim($tmpPath);
1074
		$module = array_pop(explode(' ', $tmpPath));
0 ignored issues
show
Bug introduced by
explode(' ', $tmpPath) cannot be passed to array_pop() as the parameter $array expects a reference.
Loading history...
1075
1076
		if($dir == 'skins')
1077
		{
1078
			$oAdminModel = getAdminModel('admin');
1079
			$themesInfo = $oAdminModel->getThemeList();
1080
1081
			foreach($themesInfo as $themeName => $info)
1082
			{
1083
				$skinInfos = $info->skin_infos;
1084
				if(isset($skinInfos[$module]) && $skinInfos[$module]->is_theme)
1085
				{
1086
					$themeSkinInfo = $GLOBALS['__ThemeModuleSkin__'][$module]['skins'][$skinInfos[$module]->name];
1087
					$skin_list[$skinInfos[$module]->name] = $themeSkinInfo;
0 ignored issues
show
Bug introduced by
The variable $skin_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1088
				}
1089
			}
1090
		}
1091
1092
		$siteInfo = Context::get('site_module_info');
1093
		$oMenuAdminModel = getAdminModel('menu');
1094
		$installedMenuTypes = $oMenuAdminModel->getModuleListInSitemap($siteInfo->site_srl);
1095
		$moduleName = $module;
1096
		if($moduleName === 'page')
1097
		{
1098
			$moduleName = 'ARTICLE';
1099
		}
1100
		if(array_key_exists($moduleName, $installedMenuTypes))
1101
		{
1102
			if($dir == 'skins')
1103
			{
1104
				$type = 'P';
1105
			}
1106
			else
1107
			{
1108
				$type = 'M';
1109
			}
1110
			$defaultSkinName = $this->getModuleDefaultSkin($module, $type, $site_info->site_srl);
0 ignored issues
show
Bug introduced by
The variable $site_info does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1111
1112
			if(isset($defaultSkinName))
1113
			{
1114
				$defaultSkinInfo = $this->loadSkinInfo($path, $defaultSkinName, $dir);
1115
1116
				$useDefault = new stdClass();
1117
				$useDefault->title = Context::getLang('use_site_default_skin') . ' (' . $defaultSkinInfo->title . ')';
1118
1119
				$useDefaultList['/USE_DEFAULT/'] = $useDefault;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$useDefaultList was never initialized. Although not strictly required by PHP, it is generally a good practice to add $useDefaultList = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1120
1121
				$skin_list = array_merge($useDefaultList, $skin_list);
1122
			}
1123
		}
1124
1125
		return $skin_list;
1126
	}
1127
1128
	/**
1129
	 * @brief Get skin information on a specific location
1130
	 */
1131
	function loadSkinInfo($path, $skin, $dir = 'skins')
1132
	{
1133
		// Read xml file having skin information
1134
		if(substr($path,-1)!='/') $path .= '/';
1135
		$skin_xml_file = sprintf("%s%s/%s/skin.xml", $path, $dir, $skin);
1136
		if(!file_exists($skin_xml_file)) return;
1137
		// Create XmlParser object
1138
		$oXmlParser = new XmlParser();
1139
		$_xml_obj = $oXmlParser->loadXmlFile($skin_xml_file);
1140
		// Return if no skin information is
1141
		if(!$_xml_obj->skin) return;
1142
		$xml_obj = $_xml_obj->skin;
1143
		// Skin Name
1144
		$skin_info = new stdClass();
1145
		$skin_info->title = $xml_obj->title->body;
1146
		// Author information
1147
		if($xml_obj->version && $xml_obj->attrs->version == '0.2')
1148
		{
1149
			// skin format v0.2
1150
			sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
0 ignored issues
show
Bug introduced by
The variable $date_obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1151
			$skin_info->version = $xml_obj->version->body;
1152
			$skin_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
1153
			$skin_info->homepage = $xml_obj->link->body;
1154
			$skin_info->license = $xml_obj->license->body;
1155
			$skin_info->license_link = $xml_obj->license->attrs->link;
1156
			$skin_info->description = $xml_obj->description->body;
1157
1158 View Code Duplication
			if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$author_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $author_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1159
			else $author_list = $xml_obj->author;
1160
1161 View Code Duplication
			foreach($author_list as $author)
1162
			{
1163
				$author_obj = new stdClass();
1164
				$author_obj->name = $author->name->body;
1165
				$author_obj->email_address = $author->attrs->email_address;
1166
				$author_obj->homepage = $author->attrs->link;
1167
				$skin_info->author[] = $author_obj;
1168
			}
1169
			// List extra vars
1170
			if($xml_obj->extra_vars)
1171
			{
1172
				$extra_var_groups = $xml_obj->extra_vars->group;
1173
				if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
1174
				if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
1175
1176
				foreach($extra_var_groups as $group)
1177
				{
1178
					$extra_vars = $group->var;
1179
					if(!$extra_vars)
1180
					{
1181
						continue;
1182
					}
1183
					if(!is_array($group->var)) $extra_vars = array($group->var);
1184
1185
					foreach($extra_vars as $key => $val)
1186
					{
1187
						$obj = new stdClass();
1188
						if(!$val->attrs->type) { $val->attrs->type = 'text'; }
1189
1190
						$obj->group = $group->title->body;
1191
						$obj->name = $val->attrs->name;
1192
						$obj->title = $val->title->body;
1193
						$obj->type = $val->attrs->type;
1194
						$obj->description = $val->description->body;
1195
						$obj->value = $extra_vals->{$obj->name};
0 ignored issues
show
Bug introduced by
The variable $extra_vals does not exist. Did you mean $extra_vars?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
1196
						$obj->default = $val->attrs->default;
1197
						if(strpos($obj->value, '|@|') != false) { $obj->value = explode('|@|', $obj->value); }
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($obj->value, '|@|') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
1198
						if($obj->type == 'mid_list' && !is_array($obj->value)) { $obj->value = array($obj->value); }
1199
						// Get an option list from 'select'type
1200
						if(is_array($val->options))
1201
						{
1202
							$option_count = count($val->options);
1203
1204
							for($i = 0; $i < $option_count; $i++)
1205
							{
1206
								$obj->options[$i] = new stdClass();
1207
								$obj->options[$i]->title = $val->options[$i]->title->body;
1208
								$obj->options[$i]->value = $val->options[$i]->attrs->value;
1209
							}
1210
						}
1211
						else
1212
						{
1213
							$obj->options[0] = new stdClass();
1214
							$obj->options[0]->title = $val->options->title->body;
1215
							$obj->options[0]->value = $val->options->attrs->value;
1216
						}
1217
1218
						$skin_info->extra_vars[] = $obj;
1219
					}
1220
				}
1221
			}
1222
		}
1223
		else
1224
		{
1225
			// skin format v0.1
1226
			sscanf($xml_obj->maker->attrs->date, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
1227
1228
			$skin_info->version = $xml_obj->version->body;
1229
			$skin_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
1230
			$skin_info->homepage = $xml_obj->link->body;
1231
			$skin_info->license = $xml_obj->license->body;
1232
			$skin_info->license_link = $xml_obj->license->attrs->link;
1233
			$skin_info->description = $xml_obj->maker->description->body;
1234
1235
			$skin_info->author[0] = new stdClass();
1236
			$skin_info->author[0]->name = $xml_obj->maker->name->body;
1237
			$skin_info->author[0]->email_address = $xml_obj->maker->attrs->email_address;
1238
			$skin_info->author[0]->homepage = $xml_obj->maker->attrs->link;
1239
			// Variables used in the skin
1240
			$extra_var_groups = $xml_obj->extra_vars->group;
1241
			if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
1242
			if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
1243
1244
			foreach($extra_var_groups as $group)
1245
			{
1246
				$extra_vars = $group->var;
1247
1248
				if($extra_vars)
1249
				{
1250
					if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
1251
1252
					foreach($extra_vars as $var)
1253
					{
1254
						unset($obj);
1255
						unset($options);
1256
1257
						$group = $group->title->body;
1258
						$name = $var->attrs->name;
1259
						$type = $var->attrs->type;
1260
						$title = $var->title->body;
1261
						$description = $var->description->body;
1262
						// Get an option list from 'select'type.
1263
						if(is_array($var->default))
1264
						{
1265
							$option_count = count($var->default);
1266
1267
							for($i = 0; $i < $option_count; $i++)
1268
							{
1269
								$options[$i]->title = $var->default[$i]->body;
0 ignored issues
show
Bug introduced by
The variable $options does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1270
								$options[$i]->value = $var->default[$i]->body;
1271
							}
1272
						}
1273
						else
1274
						{
1275
							$options[0]->title = $var->default->body;
1276
							$options[0]->value = $var->default->body;
1277
						}
1278
1279
						$width = $var->attrs->width;
1280
						$height = $var->attrs->height;
1281
1282
						unset($obj);
1283
						$obj->group = $group;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1284
						$obj->title = $title;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1285
						$obj->description = $description;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1286
						$obj->name = $name;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1287
						$obj->type = $type;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1288
						$obj->options = $options;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1289
						$obj->width = $width;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1290
						$obj->height = $height;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1291
						$obj->default = $options[0]->value;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1292
1293
						$skin_info->extra_vars[] = $obj;
0 ignored issues
show
Bug introduced by
The variable $obj seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1294
					}
1295
				}
1296
			}
1297
		}
1298
1299
		// colorset
1300
		$colorset = $xml_obj->colorset->color;
1301
		if($colorset)
1302
		{
1303
			if(!is_array($colorset)) $colorset = array($colorset);
1304
1305
			foreach($colorset as $color)
1306
			{
1307
				$name = $color->attrs->name;
1308
				$title = $color->title->body;
1309
				$screenshot = $color->attrs->src;
1310
				if($screenshot)
1311
				{
1312
					$screenshot = sprintf("%s%s/%s/%s", $path, $dir, $skin, $screenshot);
1313
					if(!file_exists($screenshot)) $screenshot = "";
1314
				}
1315
				else $screenshot = "";
1316
1317
				$obj = new stdClass();
1318
				$obj->name = $name;
1319
				$obj->title = $title;
1320
				$obj->screenshot = $screenshot;
1321
				$skin_info->colorset[] = $obj;
1322
			}
1323
		}
1324
		// Menu type (settings for layout)
1325
		if($xml_obj->menus->menu)
1326
		{
1327
			$menus = $xml_obj->menus->menu;
1328
			if(!is_array($menus)) $menus = array($menus);
1329
1330
			$menu_count = count($menus);
1331
			$skin_info->menu_count = $menu_count;
1332
			for($i=0;$i<$menu_count;$i++)
1333
			{
1334
				unset($obj);
1335
1336
				$obj->name = $menus[$i]->attrs->name;
0 ignored issues
show
Bug introduced by
The variable $obj does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1337
				if($menus[$i]->attrs->default == "true") $obj->default = true;
1338
				$obj->title = $menus[$i]->title->body;
1339
				$obj->maxdepth = $menus[$i]->maxdepth->body;
1340
1341
				$skin_info->menu->{$obj->name} = $obj;
1342
			}
1343
		}
1344
1345
		$thumbnail = sprintf("%s%s/%s/thumbnail.png", $path, $dir, $skin);
1346
		$skin_info->thumbnail = (file_exists($thumbnail))?$thumbnail:null;
1347
		return $skin_info;
1348
	}
1349
1350
	/**
1351
	 * @brief Return the number of modules which are registered on a virtual site
1352
	 */
1353
	function getModuleCount($site_srl, $module = null)
1354
	{
1355
		$args = new stdClass;
1356
		$args->site_srl = $site_srl;
1357
		if(!is_null($module)) $args->module = $module;
1358
		$output = executeQuery('module.getModuleCount', $args);
1359
		return $output->data->count;
1360
	}
1361
1362
	/**
1363
	 * @brief Return module configurations
1364
	 * Global configuration is used to manage board, member and others
1365
	 */
1366 View Code Duplication
	function getModuleConfig($module, $site_srl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1367
	{
1368
		$config = false;
1369
		// cache controll
1370
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1371
		if($oCacheHandler->isSupport())
1372
		{
1373
			$object_key = 'module_config:' . $module . '_' . $site_srl;
1374
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1375
			$config = $oCacheHandler->get($cache_key);
1376
		}
1377
1378
		if($config === false)
1379
		{
1380
			if(!$GLOBALS['__ModuleConfig__'][$site_srl][$module])
1381
			{
1382
				$args = new stdClass();
1383
				$args->module = $module;
1384
				$args->site_srl = $site_srl;
1385
				$output = executeQuery('module.getModuleConfig', $args);
1386
				if($output->data->config) $config = unserialize($output->data->config);
1387
				else $config = null;
1388
1389
				//insert in cache
1390
				if($oCacheHandler->isSupport())
1391
				{
1392
					$oCacheHandler->put($cache_key, $config);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1393
				}
1394
				$GLOBALS['__ModuleConfig__'][$site_srl][$module] = $config;
1395
			}
1396
			return $GLOBALS['__ModuleConfig__'][$site_srl][$module];
1397
		}
1398
1399
		return $config;
1400
	}
1401
1402
	/**
1403
	 * @brief Return the module configuration of mid
1404
	 * Manage mid configurations which depend on module
1405
	 */
1406 View Code Duplication
	function getModulePartConfig($module, $module_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1407
	{
1408
		$config = false;
1409
		// cache controll
1410
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1411
		if($oCacheHandler->isSupport())
1412
		{
1413
			$object_key = 'module_part_config:'.$module.'_'.$module_srl;
1414
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1415
			$config = $oCacheHandler->get($cache_key);
1416
		}
1417
1418
		if($config === false)
1419
		{
1420
			if(!isset($GLOBALS['__ModulePartConfig__'][$module][$module_srl]))
1421
			{
1422
				$args = new stdClass();
1423
				$args->module = $module;
1424
				$args->module_srl = $module_srl;
1425
				$output = executeQuery('module.getModulePartConfig', $args);
1426
				if($output->data->config) $config = unserialize($output->data->config);
1427
				else $config = null;
1428
1429
				//insert in cache
1430
				if($oCacheHandler->isSupport())
1431
				{
1432
					$oCacheHandler->put($cache_key, $config);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1433
				}
1434
				$GLOBALS['__ModulePartConfig__'][$module][$module_srl] = $config;
1435
			}
1436
			return $GLOBALS['__ModulePartConfig__'][$module][$module_srl];
1437
		}
1438
1439
		return $config;
1440
	}
1441
1442
	/**
1443
	 * @brief Get all of module configurations for each mid
1444
	 */
1445
	function getModulePartConfigs($module, $site_srl = 0)
1446
	{
1447
		$args = new stdClass();
1448
		$args->module = $module;
1449
		if($site_srl) $args->site_srl = $site_srl;
1450
		$output = executeQueryArray('module.getModulePartConfigs', $args);
1451
		if(!$output->toBool() || !$output->data) return array();
1452
1453
		foreach($output->data as $key => $val)
1454
		{
1455
			$result[$val->module_srl] = unserialize($val->config);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1456
		}
1457
		return $result;
0 ignored issues
show
Bug introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1458
	}
1459
1460
	/**
1461
	 * @brief Get a list of module category
1462
	 */
1463
	function getModuleCategories($moduleCategorySrl = array())
1464
	{
1465
		$args = new stdClass();
1466
		$args->moduleCategorySrl = $moduleCategorySrl;
1467
		// Get data from the DB
1468
		$output = executeQuery('module.getModuleCategories', $args);
1469
		if(!$output->toBool()) return $output;
1470
		$list = $output->data;
1471
		if(!$list) return;
1472
		if(!is_array($list)) $list = array($list);
1473
1474
		foreach($list as $val)
1475
		{
1476
			$category_list[$val->module_category_srl] = $val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$category_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $category_list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1477
		}
1478
		return $category_list;
0 ignored issues
show
Bug introduced by
The variable $category_list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1479
	}
1480
1481
	/**
1482
	 * @brief Get content from the module category
1483
	 */
1484
	function getModuleCategory($module_category_srl)
1485
	{
1486
		// Get data from the DB
1487
		$args = new stdClass;
1488
		$args->module_category_srl = $module_category_srl;
1489
		$output = executeQuery('module.getModuleCategory', $args);
1490
		if(!$output->toBool()) return $output;
1491
		return $output->data;
1492
	}
1493
1494
	/**
1495
	 * @brief Get xml information of the module
1496
	 */
1497
	function getModulesXmlInfo()
1498
	{
1499
		// Get a list of downloaded and installed modules
1500
		$searched_list = FileHandler::readDir('./modules');
1501
		$searched_count = count($searched_list);
1502
		if(!$searched_count) return;
1503
		sort($searched_list);
1504
1505
		for($i=0;$i<$searched_count;$i++)
1506
		{
1507
			// Module name
1508
			$module_name = $searched_list[$i];
1509
1510
			$path = ModuleHandler::getModulePath($module_name);
1511
			// Get information of the module
1512
			$info = $this->getModuleInfoXml($module_name);
1513
			unset($obj);
1514
1515
			if(!isset($info)) continue;
1516
			$info->module = $module_name;
1517
			$info->created_table_count = $created_table_count;
0 ignored issues
show
Bug introduced by
The variable $created_table_count does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1518
			$info->table_count = $table_count;
0 ignored issues
show
Bug introduced by
The variable $table_count does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1519
			$info->path = $path;
1520
			$info->admin_index_act = $info->admin_index_act;
1521
			$list[] = $info;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1522
		}
1523
		return $list;
0 ignored issues
show
Bug introduced by
The variable $list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1524
	}
1525
1526
	function checkNeedInstall($module_name)
1527
	{
1528
		$oDB = &DB::getInstance();
1529
		$info = null;
0 ignored issues
show
Unused Code introduced by
$info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1530
1531
		$moduledir = ModuleHandler::getModulePath($module_name);
1532
		if(file_exists(FileHandler::getRealPath($moduledir."schemas")))
1533
		{
1534
			$tmp_files = FileHandler::readDir($moduledir."schemas", '/(\.xml)$/');
1535
			$table_count = count($tmp_files);
1536
			// Check if the table is created
1537
			$created_table_count = 0;
1538 View Code Duplication
			for($j=0;$j<count($tmp_files);$j++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1539
			{
1540
				list($table_name) = explode(".",$tmp_files[$j]);
1541
				if($oDB->isTableExists($table_name)) $created_table_count ++;
1542
			}
1543
			// Check if DB is installed
1544
			if($table_count > $created_table_count) return true;
1545
			else return false;
1546
		}
1547
		return false;
1548
	}
1549
1550
	function checkNeedUpdate($module_name)
1551
	{
1552
		// Check if it is upgraded to module.class.php on each module
1553
		$oDummy = getModule($module_name, 'class');
1554
		if($oDummy && method_exists($oDummy, "checkUpdate"))
1555
		{
1556
			return $oDummy->checkUpdate();
1557
		}
1558
		return false;
1559
	}
1560
1561
	/**
1562
	 * @brief 업데이트 적용 여부 확인
1563
	 * @param array|string $update_id
1564
	 * @return Boolean
1565
	 */
1566
	public function needUpdate($update_id)
1567
	{
1568
		if(!is_array($update_id)) $update_id = array($update_id);
1569
1570
		$args = new stdClass();
1571
		$args->update_id = implode(',', $update_id);
1572
		$output = executeQueryArray('module.getModuleUpdateLog', $args);
1573
1574
		if(!!$output->error) return false;
1575
		if(!$output->data) $output->data = array();
1576
		if(count($update_id) === count($output->data)) return false;
1577
1578
		return true;
1579
	}
1580
1581
	/**
1582
	 * @brief Get a type and information of the module
1583
	 */
1584
	function getModuleList()
1585
	{
1586
		// Create DB Object
1587
		$oDB = &DB::getInstance();
1588
		// Get a list of downloaded and installed modules
1589
		$searched_list = FileHandler::readDir('./modules', '/^([a-zA-Z0-9_-]+)$/');
1590
		sort($searched_list);
1591
1592
		$searched_count = count($searched_list);
1593
		if(!$searched_count) return;
1594
1595
		for($i=0;$i<$searched_count;$i++)
1596
		{
1597
			// module name
1598
			$module_name = $searched_list[$i];
1599
1600
			$path = ModuleHandler::getModulePath($module_name);
1601
			if(!is_dir(FileHandler::getRealPath($path))) continue;
1602
1603
			// Get the number of xml files to create a table in schemas
1604
			$tmp_files = FileHandler::readDir($path.'schemas', '/(\.xml)$/');
1605
			$table_count = count($tmp_files);
1606
			// Check if the table is created
1607
			$created_table_count = 0;
1608 View Code Duplication
			for($j=0;$j<$table_count;$j++)
1609
			{
1610
				list($table_name) = explode('.',$tmp_files[$j]);
1611
				if($oDB->isTableExists($table_name)) $created_table_count ++;
1612
			}
1613
			// Get information of the module
1614
			$info = NULL;
0 ignored issues
show
Unused Code introduced by
$info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1615
			$info = $this->getModuleInfoXml($module_name);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $info is correct as $this->getModuleInfoXml($module_name) (which targets moduleModel::getModuleInfoXml()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1616
1617
			if(!$info) continue;
1618
1619
			$info->module = $module_name;
1620
			$info->category = $info->category;
1621
			$info->created_table_count = $created_table_count;
1622
			$info->table_count = $table_count;
1623
			$info->path = $path;
1624
			$info->admin_index_act = $info->admin_index_act;
1625
			// Check if DB is installed
1626
			if($table_count > $created_table_count) $info->need_install = true;
1627
			else $info->need_install = false;
1628
			// Check if it is upgraded to module.class.php on each module
1629
			$oDummy = null;
0 ignored issues
show
Unused Code introduced by
$oDummy is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1630
			$oDummy = getModule($module_name, 'class');
1631
			if($oDummy && method_exists($oDummy, "checkUpdate"))
1632
			{
1633
				$info->need_update = $oDummy->checkUpdate();
1634
			}
1635
			else
1636
			{
1637
				continue;
1638
			}
1639
1640
			$list[] = $info;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1641
		}
1642
		return $list;
0 ignored issues
show
Bug introduced by
The variable $list does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1643
	}
1644
1645
	/**
1646
	 * @brief Combine module_srls with domain of sites
1647
	 * Because XE DBHandler doesn't support left outer join,
1648
	 * it should be as same as $Output->data[]->module_srl.
1649
	 */
1650
	function syncModuleToSite(&$data)
1651
	{
1652
		if(!$data) return;
1653
1654
		if(is_array($data))
1655
		{
1656
			foreach($data as $key => $val)
1657
			{
1658
				$module_srls[] = $val->module_srl;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$module_srls was never initialized. Although not strictly required by PHP, it is generally a good practice to add $module_srls = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1659
			}
1660
			if(!count($module_srls)) return;
0 ignored issues
show
Bug introduced by
The variable $module_srls does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1661
		}
1662
		else
1663
		{
1664
			$module_srls[] = $data->module_srl;
1665
		}
1666
1667
		$args = new stdClass();
1668
		$args->module_srls = implode(',',$module_srls);
1669
		$output = executeQueryArray('module.getModuleSites', $args);
1670
		if(!$output->data) return array();
1671
		foreach($output->data as $key => $val)
1672
		{
1673
			$modules[$val->module_srl] = $val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$modules was never initialized. Although not strictly required by PHP, it is generally a good practice to add $modules = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1674
		}
1675
1676
		if(is_array($data))
1677
		{
1678
			foreach($data as $key => $val)
1679
			{
1680
				$data[$key]->domain = $modules[$val->module_srl]->domain;
0 ignored issues
show
Bug introduced by
The variable $modules does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1681
			}
1682
		}
1683
		else
1684
		{
1685
			$data->domain = $modules[$data->module_srl]->domain;
1686
		}
1687
	}
1688
1689
	/**
1690
	 * @brief Check if it is an administrator of site_module_info
1691
	 */
1692
	function isSiteAdmin($member_info, $site_srl = null)
1693
	{
1694
		if(!$member_info->member_srl) return false;
1695
		if($member_info->is_admin == 'Y') return true;
1696
1697
		$args = new stdClass();
1698 View Code Duplication
		if(!isset($site_srl))
1699
		{
1700
			$site_module_info = Context::get('site_module_info');
1701
			if(!$site_module_info) return;
1702
			$args->site_srl = $site_module_info->site_srl;
1703
		}
1704
		else
1705
		{
1706
			$args->site_srl = $site_srl;
1707
		}
1708
1709
		$args->member_srl = $member_info->member_srl;
1710
		$output = executeQuery('module.isSiteAdmin', $args);
1711
		if($output->data->member_srl == $args->member_srl) return true;
1712
		return false;
1713
	}
1714
1715
	/**
1716
	 * @brief Get admin information of the site
1717
	 */
1718
	function getSiteAdmin($site_srl)
1719
	{
1720
		$args = new stdClass;
1721
		$args->site_srl = $site_srl;
1722
		$output = executeQueryArray('module.getSiteAdmin', $args);
1723
		return $output->data;
1724
	}
1725
1726
	/**
1727
	 * @brief Get admin ID of the module
1728
	 */
1729
	function getAdminId($module_srl)
1730
	{
1731
		$obj = new stdClass();
1732
		$obj->module_srl = $module_srl;
1733
		$output = executeQueryArray('module.getAdminID', $obj);
1734
		if(!$output->toBool() || !$output->data) return;
1735
1736
		return $output->data;
1737
	}
1738
1739
	/**
1740
	 * @brief Get extra vars of the module
1741
	 * Extra information, not in the modules table
1742
	 */
1743
	function getModuleExtraVars($list_module_srl)
1744
	{
1745
		$extra_vars = array();
1746
		$get_module_srls = array();
1747
		if(!is_array($list_module_srl)) $list_module_srl = array($list_module_srl);
1748
1749
		$vars = false;
0 ignored issues
show
Unused Code introduced by
$vars is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1750
		// cache controll
1751
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1752
		if($oCacheHandler->isSupport())
1753
		{
1754
			foreach($list_module_srl as $module_srl)
1755
			{
1756
				$object_key = 'module_extra_vars:'.$module_srl;
1757
				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1758
				$vars = $oCacheHandler->get($cache_key);
1759
1760
				if($vars)
1761
				{
1762
					$extra_vars[$module_srl] = $vars;
1763
				}
1764
				else
1765
				{
1766
					$get_module_srls[] = $module_srl;
1767
				}
1768
			}
1769
		}
1770
		else
1771
		{
1772
			$get_module_srls = $list_module_srl;
1773
		}
1774
1775
		if(count($get_module_srls) > 0)
1776
		{
1777
			$args = new stdClass();
1778
			$args->module_srl = implode(',', $get_module_srls);
1779
			$output = executeQueryArray('module.getModuleExtraVars', $args);
1780
1781
			if(!$output->toBool())
1782
			{
1783
				return;
1784
			}
1785
1786
			if(!$output->data)
1787
			{
1788
				foreach($get_module_srls as $module_srl)
1789
				{
1790
					$extra_vars[$module_srl] = new stdClass;
1791
				}
1792
			}
1793
			foreach($output->data as $key => $val)
1794
			{
1795
				if(in_array($val->name, array('mid','module')) || $val->value == 'Array') continue;
1796
1797
				if(!isset($extra_vars[$val->module_srl]))
1798
				{
1799
					$extra_vars[$val->module_srl] = new stdClass();
1800
				}
1801
				$extra_vars[$val->module_srl]->{$val->name} = $val->value;
1802
1803 View Code Duplication
				if($oCacheHandler->isSupport())
1804
				{
1805
					$object_key = 'module_extra_vars:'.$val->module_srl;
1806
					$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1807
					$oCacheHandler->put($cache_key, $extra_vars[$val->module_srl]);
1808
				}
1809
			}
1810
		}
1811
1812
		return $extra_vars;
1813
	}
1814
1815
	/**
1816
	 * @brief Get skin information of the module
1817
	 */
1818 View Code Duplication
	function getModuleSkinVars($module_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1819
	{
1820
		$skin_vars = false;
1821
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1822
		if($oCacheHandler->isSupport())
1823
		{
1824
			$object_key = 'module_skin_vars:'.$module_srl;
1825
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1826
			$skin_vars = $oCacheHandler->get($cache_key);
1827
		}
1828
1829
		if($skin_vars === false)
1830
		{
1831
			$args = new stdClass();
1832
			$args->module_srl = $module_srl;
1833
			$output = executeQueryArray('module.getModuleSkinVars',$args);
1834
			if(!$output->toBool()) return;
1835
1836
			$skin_vars = array();
1837
			foreach($output->data as $vars)
1838
			{
1839
				$skin_vars[$vars->name] = $vars;
1840
			}
1841
1842
			if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1843
		}
1844
1845
		return $skin_vars;
1846
	}
1847
1848
	/**
1849
	 * Get default skin name
1850
	 */
1851
	function getModuleDefaultSkin($module_name, $skin_type = 'P', $site_srl = 0, $updateCache = true)
1852
	{
1853
		$target = ($skin_type == 'M') ? 'mskin' : 'skin';
1854
		if(!$site_srl) $site_srl = 0;
1855
1856
		$designInfoFile = sprintf(_XE_PATH_.'files/site_design/design_%s.php', $site_srl);
1857
		if(is_readable($designInfoFile))
1858
		{
1859
			include($designInfoFile);
1860
1861
			$skinName = $designInfo->module->{$module_name}->{$target};
0 ignored issues
show
Bug introduced by
The variable $designInfo does not exist. Did you mean $designInfoFile?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
1862
		}
1863
		if(!$skinName)
0 ignored issues
show
Bug introduced by
The variable $skinName does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1864
		{
1865
			$dir = ($skin_type == 'M') ? 'm.skins/' : 'skins/';
1866
			$moduleSkinPath = ModuleHandler::getModulePath($module_name).$dir;
1867
1868
			if(is_dir($moduleSkinPath.'default'))
1869
			{
1870
				$skinName = 'default';
1871
			}
1872
			else if(is_dir($moduleSkinPath.'xe_default'))
1873
			{
1874
				$skinName = 'xe_default';
1875
			}
1876
			else
1877
			{
1878
				$skins = FileHandler::readDir($moduleSkinPath);
1879
				if(count($skins) > 0)
1880
				{
1881
					$skinName = $skins[0];
1882
				}
1883
				else
1884
				{
1885
					$skinName = NULL;
1886
				}
1887
			}
1888
1889
			if($updateCache && $skinName)
0 ignored issues
show
Bug Best Practice introduced by
The expression $skinName of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1890
			{
1891
				if(!isset($designInfo->module->{$module_name})) $designInfo->module->{$module_name} = new stdClass();
0 ignored issues
show
Bug introduced by
The variable $designInfo does not exist. Did you mean $designInfoFile?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
1892
				$designInfo->module->{$module_name}->{$target} = $skinName;
0 ignored issues
show
Bug introduced by
The variable $designInfo does not exist. Did you mean $designInfoFile?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
1893
1894
				$oAdminController = getAdminController('admin');
1895
				$oAdminController->makeDefaultDesignFile($designInfo, $site_srl);
0 ignored issues
show
Bug introduced by
The variable $designInfo does not exist. Did you mean $designInfoFile?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
1896
			}
1897
		}
1898
1899
		return $skinName;
1900
	}
1901
1902
	/**
1903
	 * @brief Combine skin information with module information
1904
	 */
1905
	function syncSkinInfoToModuleInfo(&$module_info)
1906
	{
1907
		if(!$module_info->module_srl) return;
1908
1909
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
0 ignored issues
show
Unused Code introduced by
$oCacheHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1910
		if(Mobile::isFromMobilePhone())
1911
		{
1912
			$skin_vars = $this->getModuleMobileSkinVars($module_info->module_srl);
1913
		}
1914
		else
1915
		{
1916
			$skin_vars = $this->getModuleSkinVars($module_info->module_srl);
1917
		}
1918
1919
		if(!$skin_vars) return;
1920
1921
		foreach($skin_vars as $name => $val)
0 ignored issues
show
Bug introduced by
The expression $skin_vars of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
1922
		{
1923
			if(isset($module_info->{$name})) continue;
1924
			$module_info->{$name} = $val->value;
1925
		}
1926
	}
1927
1928
	/**
1929
	 * Get mobile skin information of the module
1930
	 * @param $module_srl Sequence of module
1931
	 * @return array
1932
	 */
1933 View Code Duplication
	function getModuleMobileSkinVars($module_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1934
	{
1935
		$skin_vars = false;
1936
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1937
		if($oCacheHandler->isSupport())
1938
		{
1939
			$object_key = 'module_mobile_skin_vars:'.$module_srl;
1940
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1941
			$skin_vars = $oCacheHandler->get($cache_key);
1942
		}
1943
1944
		if($skin_vars === false)
1945
		{
1946
			$args = new stdClass();
1947
			$args->module_srl = $module_srl;
1948
			$output = executeQueryArray('module.getModuleMobileSkinVars',$args);
1949
			if(!$output->toBool() || !$output->data) return;
1950
1951
			$skin_vars = array();
1952
			foreach($output->data as $vars)
1953
			{
1954
				$skin_vars[$vars->name] = $vars;
1955
			}
1956
1957
			if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1958
		}
1959
1960
		return $skin_vars;
1961
	}
1962
1963
	/**
1964
	 * Combine skin information with module information
1965
	 * @param $module_info Module information
1966
	 */
1967
	function syncMobileSkinInfoToModuleInfo(&$module_info)
1968
	{
1969
		if(!$module_info->module_srl) return;
1970
		$skin_vars = false;
1971
		// cache controll
1972
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1973 View Code Duplication
		if($oCacheHandler->isSupport())
1974
		{
1975
			$object_key = 'module_mobile_skin_vars:'.$module_info->module_srl;
1976
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1977
			$skin_vars = $oCacheHandler->get($cache_key);
1978
		}
1979 View Code Duplication
		if($skin_vars === false)
1980
		{
1981
			$args = new stdClass;
1982
			$args->module_srl = $module_info->module_srl;
1983
			$output = executeQueryArray('module.getModuleMobileSkinVars',$args);
1984
			if(!$output->toBool()) return;
1985
			$skin_vars = $output->data;
1986
1987
			//insert in cache
1988
			if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1989
		}
1990
		if(!$skin_vars) return;
1991
1992
		foreach($output->data as $val)
0 ignored issues
show
Bug introduced by
The variable $output does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1993
		{
1994
			if(isset($module_info->{$val->name})) continue;
1995
			$module_info->{$val->name} = $val->value;
1996
		}
1997
	}
1998
1999
	/**
2000
	 * @brief Return permission by using module info, xml info and member info
2001
	 */
2002
	function getGrant($module_info, $member_info, $xml_info = '')
2003
	{
2004
		$grant = new stdClass();
2005
2006
		if(!$xml_info)
2007
		{
2008
			$module = $module_info->module;
2009
			$xml_info = $this->getModuleActionXml($module);
2010
		}
2011
		// Set variables to grant group permission
2012
		$module_srl = $module_info->module_srl;
2013
		$grant_info = $xml_info->grant;
2014 View Code Duplication
		if($member_info->member_srl)
2015
		{
2016
			if(is_array($member_info->group_list)) $group_list = array_keys($member_info->group_list);
2017
			else $group_list = array();
2018
		}
2019
		else
2020
		{
2021
			$group_list = array();
2022
		}
2023
		// If module_srl doesn't exist(if unable to set permissions)
2024
		if(!$module_srl)
2025
		{
2026
			$grant->access = true;
2027
			if($this->isSiteAdmin($member_info, $module_info->site_srl))
2028
			{
2029
				$grant->access = $grant->manager = $grant->is_site_admin = true;
2030
			}
2031
2032
			$grant->is_admin = $grant->manager = ($member_info->is_admin == 'Y') ? true : false;
2033
		}
2034
		else
2035
		{
2036
			// If module_srl exists
2037
			// Get a type of granted permission
2038
			$grant->access = $grant->manager = $grant->is_site_admin = ($member_info->is_admin=='Y'||$this->isSiteAdmin($member_info, $module_info->site_srl))?true:false;
2039
			$grant->is_admin = ($member_info->is_admin == 'Y') ? true : false;
2040
			// If a just logged-in member is, check if the member is a module administrator
2041
			if(!$grant->manager && $member_info->member_srl)
2042
			{
2043
				$args = new stdClass();
2044
				$args->module_srl = $module_srl;
2045
				$args->member_srl = $member_info->member_srl;
2046
				$output = executeQuery('module.getModuleAdmin',$args);
2047
				if($output->data && $output->data->member_srl == $member_info->member_srl) $grant->manager = true;
2048
			}
2049
			// If not an administrator, get information from the DB and grant manager privilege.
2050
			if(!$grant->manager)
2051
			{
2052
				$args = new stdClass();
2053
				// If planet, get permission settings from the planet home
2054
				if($module_info->module == 'planet')
2055
				{
2056
					$output = executeQueryArray('module.getPlanetGrants', $args);
2057
				}
2058
				else
2059
				{
2060
					$args = new stdClass;
2061
					$args->module_srl = $module_srl;
2062
					$output = executeQueryArray('module.getModuleGrants', $args);
2063
				}
2064
2065
				$grant_exists = $granted = array();
2066
2067
				if($output->data)
2068
				{
2069
					// Arrange names and groups who has privileges
2070
					foreach($output->data as $val)
2071
					{
2072
						$grant_exists[$val->name] = true;
2073
						if($granted[$val->name]) continue;
2074
						// Log-in member only
2075
						if($val->group_srl == -1)
2076
						{
2077
							$granted[$val->name] = true;
2078
							if($member_info->member_srl) $grant->{$val->name} = true;
2079
							// Site-joined member only
2080
						}
2081
						elseif($val->group_srl == -2)
2082
						{
2083
							$granted[$val->name] = true;
2084
							// Do not grant any permission for non-logged member
2085
							if(!$member_info->member_srl) $grant->{$val->name} = false;
2086
							// Log-in member
2087
							else
2088
							{
2089
								$site_module_info = Context::get('site_module_info');
2090
								// Permission granted if no information of the currently connected site exists
2091
								if(!$site_module_info->site_srl) $grant->{$val->name} = true;
2092
								// Permission is not granted if information of the currently connected site exists
2093
								elseif(count($group_list)) $grant->{$val->name} = true;
2094
							}
2095
							// All of non-logged members
2096
						}
2097
						elseif($val->group_srl == -3)
2098
						{
2099
							$granted[$val->name] = true;
2100
							$grant->{$val->name} = ($grant->is_admin || $grant->is_site_admin);
2101
						}
2102
						elseif($val->group_srl == 0)
2103
						{
2104
							$granted[$val->name] = true;
2105
							$grant->{$val->name} = true;
2106
							// If a target is a group
2107
						}
2108
						else
2109
						{
2110
							if($group_list && count($group_list) && in_array($val->group_srl, $group_list))
0 ignored issues
show
Bug Best Practice introduced by
The expression $group_list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2111
							{
2112
								$grant->{$val->name} = true;
2113
								$granted[$val->name] = true;
2114
							}
2115
						}
2116
					}
2117
				}
2118
				// Separate processing for the virtual group access
2119
				if(!$grant_exists['access']) $grant->access = true;
2120
				if(count($grant_info))
2121
				{
2122
					foreach($grant_info as  $grant_name => $grant_item)
2123
					{
2124
						if($grant_exists[$grant_name]) continue;
2125
						switch($grant_item->default)
2126
						{
2127
							case 'guest' :
2128
								$grant->{$grant_name} = true;
2129
								break;
2130
							case 'member' :
2131
								if($member_info->member_srl) $grant->{$grant_name} = true;
2132
								else $grant->{$grant_name} = false;
2133
								break;
2134
							case 'site' :
2135
								$site_module_info = Context::get('site_module_info');
2136
								if($member_info->member_srl && (($site_module_info->site_srl && count($group_list)) || !$site_module_info->site_srl)) $grant->{$grant_name} = true;
2137
								else $grant->{$grant_name} = false;
2138
								break;
2139
							case 'manager' :
2140
							case 'root' :
2141
								if($member_info->is_admin == 'Y') $grant->{$grant_name} = true;
2142
								else $grant->{$grant_name} = false;
2143
								break;
2144
						}
2145
					}
2146
				}
2147
			}
2148
			// Set true to grant all privileges if an administrator is
2149
			if($grant->manager)
2150
			{
2151
				$grant->access = true;
2152
				if(count($grant_info))
2153
				{
2154
					foreach($grant_info as $key => $val)
2155
					{
2156
						$grant->{$key} = true;
2157
					}
2158
				}
2159
			}
2160
		}
2161
		return $grant;
2162
	}
2163
2164
	function getModuleFileBox($module_filebox_srl)
2165
	{
2166
		$args = new stdClass();
2167
		$args->module_filebox_srl = $module_filebox_srl;
2168
		return executeQuery('module.getModuleFileBox', $args);
2169
	}
2170
2171
	function getModuleFileBoxList()
2172
	{
2173
		$oModuleModel = getModel('module');
2174
2175
		$args = new stdClass();
2176
		$args->page = Context::get('page');
2177
		$args->list_count = 5;
2178
		$args->page_count = 5;
2179
		$output = executeQuery('module.getModuleFileBoxList', $args);
2180
		$output = $oModuleModel->unserializeAttributes($output);
2181
		return $output;
2182
	}
2183
2184
	function unserializeAttributes($module_filebox_list)
2185
	{
2186
		if(is_array($module_filebox_list->data))
2187
		{
2188
			foreach($module_filebox_list->data as &$item)
2189
			{
2190
				if(empty($item->comment))
2191
				{
2192
					continue;
2193
				}
2194
2195
				$attributes = explode(';', $item->comment);
2196
				foreach($attributes as $attribute)
2197
				{
2198
					$values = explode(':', $attribute);
2199
					if((count($values) % 2) ==1)
2200
					{
2201
						for($i=2;$i<count($values);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2202
						{
2203
							$values[1].=":".$values[$i];
2204
						}
2205
					}
2206
					$atts[$values[0]]=$values[1];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$atts was never initialized. Although not strictly required by PHP, it is generally a good practice to add $atts = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2207
				}
2208
				$item->attributes = $atts;
0 ignored issues
show
Bug introduced by
The variable $atts does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2209
				unset($atts);
2210
			}
2211
		}
2212
		return $module_filebox_list;
2213
	}
2214
2215
	function getFileBoxListHtml()
2216
	{
2217
		$logged_info = Context::get('logged_info');
2218
		if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');
2219
		$link = parse_url($_SERVER["HTTP_REFERER"]);
2220
		$link_params = explode('&',$link['query']);
2221
		foreach ($link_params as $param)
2222
		{
2223
			$param = explode("=",$param);
2224
			if($param[0] == 'selected_widget') $selected_widget = $param[1];
2225
		}
2226
		$oWidgetModel = getModel('widget');
2227
		if($selected_widget) $widget_info = $oWidgetModel->getWidgetInfo($selected_widget);
0 ignored issues
show
Bug introduced by
The variable $selected_widget does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2228
		Context::set('allow_multiple', $widget_info->extra_var->images->allow_multiple);
0 ignored issues
show
Bug introduced by
The variable $widget_info does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2229
2230
		$oModuleModel = getModel('module');
2231
		$output = $oModuleModel->getModuleFileBoxList();
2232
		Context::set('filebox_list', $output->data);
2233
2234
		$page = Context::get('page');
2235
		if (!$page) $page = 1;
2236
		Context::set('page', $page);
2237
		Context::set('page_navigation', $output->page_navigation);
2238
2239
		$security = new Security();
2240
		$security->encodeHTML('filebox_list..comment', 'filebox_list..attributes.');
2241
2242
		$oTemplate = &TemplateHandler::getInstance();
2243
		$html = $oTemplate->compile(_XE_PATH_ . 'modules/module/tpl/', 'filebox_list_html');
2244
2245
		$this->add('html', $html);
2246
	}
2247
2248
	function getModuleFileBoxPath($module_filebox_srl)
2249
	{
2250
		return sprintf("./files/attach/filebox/%s",getNumberingPath($module_filebox_srl,3));
2251
	}
2252
2253
	/**
2254
	 * @brief Return ruleset cache file path
2255
	 * @param module, act
2256
	 */
2257
	function getValidatorFilePath($module, $ruleset, $mid=null)
2258
	{
2259
		// load dynamic ruleset xml file
2260
		if(strpos($ruleset, '@') !== false)
2261
		{
2262
			$rulsetFile = str_replace('@', '', $ruleset);
2263
			$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile);
2264
			return FileHandler::getRealPath($xml_file);
2265
		}
2266
		else if (strpos($ruleset, '#') !== false)
2267
		{
2268
			$rulsetFile = str_replace('#', '', $ruleset).'.'.$mid;
2269
			$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile);
2270
			if(is_readable($xml_file))
2271
				return FileHandler::getRealPath($xml_file);
2272
			else{
2273
				$ruleset = str_replace('#', '', $ruleset);
2274
			}
2275
2276
		}
2277
		// Get a path of the requested module. Return if not exists.
2278
		$class_path = ModuleHandler::getModulePath($module);
2279
		if(!$class_path) return;
2280
2281
		// Check if module.xml exists in the path. Return if not exist
2282
		$xml_file = sprintf("%sruleset/%s.xml", $class_path, $ruleset);
2283
		if(!file_exists($xml_file)) return;
2284
2285
		return $xml_file;
2286
	}
2287
2288
	function getLangListByLangcodeForAutoComplete()
2289
	{
2290
		$keyword = Context::get('search_keyword');
0 ignored issues
show
Unused Code introduced by
$keyword is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2291
2292
		$requestVars = Context::getRequestVars();
2293
2294
		$args = new stdClass;
2295
		$args->site_srl = (int)$requestVars->site_srl;
2296
		$args->page = 1; // /< Page
2297
		$args->list_count = 100; // /< the number of posts to display on a single page
2298
		$args->page_count = 5; // /< the number of pages that appear in the page navigation
2299
		$args->sort_index = 'name';
2300
		$args->order_type = 'asc';
2301
		$args->search_keyword = Context::get('search_keyword'); // /< keyword to search*/
2302
2303
		$output = executeQueryArray('module.getLangListByLangcode', $args);
2304
2305
		$list = array();
2306
2307
		if($output->toBool())
2308
		{
2309
			foreach((array)$output->data as $code_info)
2310
			{
2311
				unset($codeInfo);
2312
				$codeInfo = array('name'=>'$user_lang->'.$code_info->name, 'value'=>$code_info->value);
2313
				$list[] = $codeInfo;
2314
			}
2315
		}
2316
		$this->add('results', $list);
2317
	}
2318
2319
	/**
2320
	 * @brief already instance created module list
2321
	 */
2322
	function getModuleListByInstance($site_srl = 0, $columnList = array())
2323
	{
2324
		$args = new stdClass();
2325
		$args->site_srl = $site_srl;
2326
		$output = executeQueryArray('module.getModuleListByInstance', $args, $columnList);
2327
		return $output;
2328
	}
2329
2330
	function getLangByLangcode()
2331
	{
2332
		$langCode = Context::get('langCode');
2333
		if (!$langCode) return;
2334
2335
		$oModuleController = getController('module');
2336
		$oModuleController->replaceDefinedLangCode($langCode);
2337
2338
		$this->add('lang', $langCode);
2339
	}
2340
}
2341
/* End of file module.model.php */
2342
/* Location: ./modules/module/module.model.php */
2343