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
Pull Request — develop (#1930)
by
unknown
13:51
created

moduleModel::getModulePartConfigs()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 6
nop 2
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
		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
			$url_info = parse_url($request_url);
101
			$hostname = $url_info['host'];
102
			$path = $url_info['path'];
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, $url_info['port']&&$url_info['port']!=80?':'.$url_info['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
938
					$index = $action->attrs->index;
939
					$admin_index = $action->attrs->admin_index;
940
					$setup_index = $action->attrs->setup_index;
941
					$simple_setup_index = $action->attrs->simple_setup_index;
942
					$menu_index = $action->attrs->menu_index;
943
944
					$info->action->{$name} = new stdClass();
945
					$info->action->{$name}->type = $type;
946
					$info->action->{$name}->grant = $grant;
947
					$info->action->{$name}->standalone = $standalone;
948
					$info->action->{$name}->ruleset = $ruleset;
949
					$info->action->{$name}->method = $method;
950
					if($action->attrs->menu_name)
951
					{
952
						if($menu_index == 'true')
953
						{
954
							$info->menu->{$action->attrs->menu_name}->index = $name;
955
							$buff[] = sprintf('$info->menu->%s->index=\'%s\';', $action->attrs->menu_name, $name);
956
						}
957
						if(is_array($info->menu->{$action->attrs->menu_name}->acts))
958
						{
959
							$info->menu->{$action->attrs->menu_name}->acts[] = $name;
960
							$currentKey = array_search($name, $info->menu->{$action->attrs->menu_name}->acts);
961
						}
962
963
						$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...
964
						$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...
965
					}
966
967
					$buff[] = sprintf('$info->action->%s = new stdClass;', $name);
968
					$buff[] = sprintf('$info->action->%s->type=\'%s\';', $name, $type);
969
					$buff[] = sprintf('$info->action->%s->grant=\'%s\';', $name, $grant);
970
					$buff[] = sprintf('$info->action->%s->standalone=\'%s\';', $name, $standalone);
971
					$buff[] = sprintf('$info->action->%s->ruleset=\'%s\';', $name, $ruleset);
972
					$buff[] = sprintf('$info->action->%s->method=\'%s\';', $name, $method);
973
974
					if($index=='true')
975
					{
976
						$default_index_act = $name;
977
						$info->default_index_act = $name;
978
					}
979
					if($admin_index=='true')
980
					{
981
						$admin_index_act = $name;
982
						$info->admin_index_act = $name;
983
					}
984
					if($setup_index=='true')
985
					{
986
						$setup_index_act = $name;
987
						$info->setup_index_act = $name;
988
					}
989
					if($simple_setup_index=='true')
990
					{
991
						$simple_setup_index_act = $name;
992
						$info->simple_setup_index_act = $name;
993
					}
994
				}
995
			}
996
			$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...
997
			$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...
998
			$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...
999
			$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...
1000
1001
			$buff[] = 'return $info;';
1002
1003
			$buff = implode(PHP_EOL, $buff);
1004
1005
			FileHandler::writeFile($cache_file, $buff);
1006
1007
			return $info;
1008
		}
1009
1010
		if(file_exists($cache_file)) return include($cache_file);
1011
	}
1012
1013
	/**
1014
	 * Get a skin list for js API.
1015
	 * return void
1016
	 */
1017
	public function getModuleSkinInfoList()
1018
	{
1019
		$module = Context::get('module_type');
1020
1021
		if($module == 'ARTICLE')
1022
		{
1023
			$module = 'page';
1024
		}
1025
1026
		$skinType = Context::get('skin_type');
1027
1028
		$path = ModuleHandler::getModulePath($module);
1029
		$dir = ($skinType == 'M') ? 'm.skins' : 'skins';
1030
		$skin_list = $this->getSkins($path, $dir);
1031
1032
		$this->add('skin_info_list', $skin_list);
1033
	}
1034
1035
	/**
1036
	 * @brief Get a list of skins for the module
1037
	 * Return file analysis of skin and skin.xml
1038
	 */
1039
	function getSkins($path, $dir = 'skins')
1040
	{
1041
		if(substr($path, -1) == '/')
1042
		{
1043
			$path = substr($path, 0, -1);
1044
		}
1045
1046
		$skin_path = sprintf("%s/%s/", $path, $dir);
1047
		$list = FileHandler::readDir($skin_path);
1048
		if(!count($list)) return;
1049
1050
		natcasesort($list);
1051
1052
		foreach($list as $skin_name)
1053
		{
1054
			if(!is_dir($skin_path . $skin_name))
1055
			{
1056
				continue;
1057
			}
1058
			unset($skin_info);
1059
			$skin_info = $this->loadSkinInfo($path, $skin_name, $dir);
1060
			if(!$skin_info)
1061
			{
1062
				$skin_info = new stdClass();
1063
				$skin_info->title = $skin_name;
1064
			}
1065
1066
			$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...
1067
		}
1068
1069
		$tmpPath = strtr($path, array('/' => ' '));
1070
		$tmpPath = trim($tmpPath);
1071
		$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...
1072
1073
		if($dir == 'skins')
1074
		{
1075
			$oAdminModel = getAdminModel('admin');
1076
			$themesInfo = $oAdminModel->getThemeList();
1077
1078
			foreach($themesInfo as $themeName => $info)
1079
			{
1080
				$skinInfos = $info->skin_infos;
1081
				if(isset($skinInfos[$module]) && $skinInfos[$module]->is_theme)
1082
				{
1083
					$themeSkinInfo = $GLOBALS['__ThemeModuleSkin__'][$module]['skins'][$skinInfos[$module]->name];
1084
					$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...
1085
				}
1086
			}
1087
		}
1088
1089
		$siteInfo = Context::get('site_module_info');
1090
		$oMenuAdminModel = getAdminModel('menu');
1091
		$installedMenuTypes = $oMenuAdminModel->getModuleListInSitemap($siteInfo->site_srl);
1092
		$moduleName = $module;
1093
		if($moduleName === 'page')
1094
		{
1095
			$moduleName = 'ARTICLE';
1096
		}
1097
		if(array_key_exists($moduleName, $installedMenuTypes))
1098
		{
1099
			if($dir == 'skins')
1100
			{
1101
				$type = 'P';
1102
			}
1103
			else
1104
			{
1105
				$type = 'M';
1106
			}
1107
			$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...
1108
1109
			if(isset($defaultSkinName))
1110
			{
1111
				$defaultSkinInfo = $this->loadSkinInfo($path, $defaultSkinName, $dir);
1112
1113
				$useDefault = new stdClass();
1114
				$useDefault->title = Context::getLang('use_site_default_skin') . ' (' . $defaultSkinInfo->title . ')';
1115
1116
				$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...
1117
1118
				$skin_list = array_merge($useDefaultList, $skin_list);
1119
			}
1120
		}
1121
1122
		return $skin_list;
1123
	}
1124
1125
	/**
1126
	 * @brief Get skin information on a specific location
1127
	 */
1128
	function loadSkinInfo($path, $skin, $dir = 'skins')
1129
	{
1130
		// Read xml file having skin information
1131
		if(substr($path,-1)!='/') $path .= '/';
1132
		$skin_xml_file = sprintf("%s%s/%s/skin.xml", $path, $dir, $skin);
1133
		if(!file_exists($skin_xml_file)) return;
1134
		// Create XmlParser object
1135
		$oXmlParser = new XmlParser();
1136
		$_xml_obj = $oXmlParser->loadXmlFile($skin_xml_file);
1137
		// Return if no skin information is
1138
		if(!$_xml_obj->skin) return;
1139
		$xml_obj = $_xml_obj->skin;
1140
		// Skin Name
1141
		$skin_info = new stdClass();
1142
		$skin_info->title = $xml_obj->title->body;
1143
		// Author information
1144
		if($xml_obj->version && $xml_obj->attrs->version == '0.2')
1145
		{
1146
			// skin format v0.2
1147
			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...
1148
			$skin_info->version = $xml_obj->version->body;
1149
			$skin_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
1150
			$skin_info->homepage = $xml_obj->link->body;
1151
			$skin_info->license = $xml_obj->license->body;
1152
			$skin_info->license_link = $xml_obj->license->attrs->link;
1153
			$skin_info->description = $xml_obj->description->body;
1154
1155 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...
1156
			else $author_list = $xml_obj->author;
1157
1158 View Code Duplication
			foreach($author_list as $author)
1159
			{
1160
				$author_obj = new stdClass();
1161
				$author_obj->name = $author->name->body;
1162
				$author_obj->email_address = $author->attrs->email_address;
1163
				$author_obj->homepage = $author->attrs->link;
1164
				$skin_info->author[] = $author_obj;
1165
			}
1166
			// List extra vars
1167
			if($xml_obj->extra_vars)
1168
			{
1169
				$extra_var_groups = $xml_obj->extra_vars->group;
1170
				if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
1171
				if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
1172
1173
				foreach($extra_var_groups as $group)
1174
				{
1175
					$extra_vars = $group->var;
1176
					if(!$extra_vars)
1177
					{
1178
						continue;
1179
					}
1180
					if(!is_array($group->var)) $extra_vars = array($group->var);
1181
1182
					foreach($extra_vars as $key => $val)
1183
					{
1184
						$obj = new stdClass();
1185
						if(!$val->attrs->type) { $val->attrs->type = 'text'; }
1186
1187
						$obj->group = $group->title->body;
1188
						$obj->name = $val->attrs->name;
1189
						$obj->title = $val->title->body;
1190
						$obj->type = $val->attrs->type;
1191
						$obj->description = $val->description->body;
1192
						$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...
1193
						$obj->default = $val->attrs->default;
1194
						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...
1195
						if($obj->type == 'mid_list' && !is_array($obj->value)) { $obj->value = array($obj->value); }
1196
						// Get an option list from 'select'type
1197
						if(is_array($val->options))
1198
						{
1199
							$option_count = count($val->options);
1200
1201
							for($i = 0; $i < $option_count; $i++)
1202
							{
1203
								$obj->options[$i] = new stdClass();
1204
								$obj->options[$i]->title = $val->options[$i]->title->body;
1205
								$obj->options[$i]->value = $val->options[$i]->attrs->value;
1206
							}
1207
						}
1208
						else
1209
						{
1210
							$obj->options[0] = new stdClass();
1211
							$obj->options[0]->title = $val->options->title->body;
1212
							$obj->options[0]->value = $val->options->attrs->value;
1213
						}
1214
1215
						$skin_info->extra_vars[] = $obj;
1216
					}
1217
				}
1218
			}
1219
		}
1220
		else
1221
		{
1222
			// skin format v0.1
1223
			sscanf($xml_obj->maker->attrs->date, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
1224
1225
			$skin_info->version = $xml_obj->version->body;
1226
			$skin_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
1227
			$skin_info->homepage = $xml_obj->link->body;
1228
			$skin_info->license = $xml_obj->license->body;
1229
			$skin_info->license_link = $xml_obj->license->attrs->link;
1230
			$skin_info->description = $xml_obj->maker->description->body;
1231
1232
			$skin_info->author[0] = new stdClass();
1233
			$skin_info->author[0]->name = $xml_obj->maker->name->body;
1234
			$skin_info->author[0]->email_address = $xml_obj->maker->attrs->email_address;
1235
			$skin_info->author[0]->homepage = $xml_obj->maker->attrs->link;
1236
			// Variables used in the skin
1237
			$extra_var_groups = $xml_obj->extra_vars->group;
1238
			if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
1239
			if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
1240
1241
			foreach($extra_var_groups as $group)
1242
			{
1243
				$extra_vars = $group->var;
1244
1245
				if($extra_vars)
1246
				{
1247
					if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
1248
1249
					foreach($extra_vars as $var)
1250
					{
1251
						unset($obj);
1252
						unset($options);
1253
1254
						$group = $group->title->body;
1255
						$name = $var->attrs->name;
1256
						$type = $var->attrs->type;
1257
						$title = $var->title->body;
1258
						$description = $var->description->body;
1259
						// Get an option list from 'select'type.
1260
						if(is_array($var->default))
1261
						{
1262
							$option_count = count($var->default);
1263
1264
							for($i = 0; $i < $option_count; $i++)
1265
							{
1266
								$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...
1267
								$options[$i]->value = $var->default[$i]->body;
1268
							}
1269
						}
1270
						else
1271
						{
1272
							$options[0]->title = $var->default->body;
1273
							$options[0]->value = $var->default->body;
1274
						}
1275
1276
						$width = $var->attrs->width;
1277
						$height = $var->attrs->height;
1278
1279
						unset($obj);
1280
						$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...
1281
						$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...
1282
						$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...
1283
						$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...
1284
						$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...
1285
						$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...
1286
						$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...
1287
						$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...
1288
						$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...
1289
1290
						$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...
1291
					}
1292
				}
1293
			}
1294
		}
1295
1296
		// colorset
1297
		$colorset = $xml_obj->colorset->color;
1298
		if($colorset)
1299
		{
1300
			if(!is_array($colorset)) $colorset = array($colorset);
1301
1302
			foreach($colorset as $color)
1303
			{
1304
				$name = $color->attrs->name;
1305
				$title = $color->title->body;
1306
				$screenshot = $color->attrs->src;
1307
				if($screenshot)
1308
				{
1309
					$screenshot = sprintf("%s%s/%s/%s", $path, $dir, $skin, $screenshot);
1310
					if(!file_exists($screenshot)) $screenshot = "";
1311
				}
1312
				else $screenshot = "";
1313
1314
				$obj = new stdClass();
1315
				$obj->name = $name;
1316
				$obj->title = $title;
1317
				$obj->screenshot = $screenshot;
1318
				$skin_info->colorset[] = $obj;
1319
			}
1320
		}
1321
		// Menu type (settings for layout)
1322
		if($xml_obj->menus->menu)
1323
		{
1324
			$menus = $xml_obj->menus->menu;
1325
			if(!is_array($menus)) $menus = array($menus);
1326
1327
			$menu_count = count($menus);
1328
			$skin_info->menu_count = $menu_count;
1329
			for($i=0;$i<$menu_count;$i++)
1330
			{
1331
				unset($obj);
1332
1333
				$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...
1334
				if($menus[$i]->attrs->default == "true") $obj->default = true;
1335
				$obj->title = $menus[$i]->title->body;
1336
				$obj->maxdepth = $menus[$i]->maxdepth->body;
1337
1338
				$skin_info->menu->{$obj->name} = $obj;
1339
			}
1340
		}
1341
1342
		$thumbnail = sprintf("%s%s/%s/thumbnail.png", $path, $dir, $skin);
1343
		$skin_info->thumbnail = (file_exists($thumbnail))?$thumbnail:null;
1344
		return $skin_info;
1345
	}
1346
1347
	/**
1348
	 * @brief Return the number of modules which are registered on a virtual site
1349
	 */
1350
	function getModuleCount($site_srl, $module = null)
1351
	{
1352
		$args = new stdClass;
1353
		$args->site_srl = $site_srl;
1354
		if(!is_null($module)) $args->module = $module;
1355
		$output = executeQuery('module.getModuleCount', $args);
1356
		return $output->data->count;
1357
	}
1358
1359
	/**
1360
	 * @brief Return module configurations
1361
	 * Global configuration is used to manage board, member and others
1362
	 */
1363 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...
1364
	{
1365
		$config = false;
1366
		// cache controll
1367
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1368
		if($oCacheHandler->isSupport())
1369
		{
1370
			$object_key = 'module_config:' . $module . '_' . $site_srl;
1371
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1372
			$config = $oCacheHandler->get($cache_key);
1373
		}
1374
1375
		if($config === false)
1376
		{
1377
			if(!$GLOBALS['__ModuleConfig__'][$site_srl][$module])
1378
			{
1379
				$args = new stdClass();
1380
				$args->module = $module;
1381
				$args->site_srl = $site_srl;
1382
				$output = executeQuery('module.getModuleConfig', $args);
1383
				if($output->data->config) $config = unserialize($output->data->config);
1384
				else $config = null;
1385
1386
				//insert in cache
1387
				if($oCacheHandler->isSupport())
1388
				{
1389
					$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...
1390
				}
1391
				$GLOBALS['__ModuleConfig__'][$site_srl][$module] = $config;
1392
			}
1393
			return $GLOBALS['__ModuleConfig__'][$site_srl][$module];
1394
		}
1395
1396
		return $config;
1397
	}
1398
1399
	/**
1400
	 * @brief Return the module configuration of mid
1401
	 * Manage mid configurations which depend on module
1402
	 */
1403 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...
1404
	{
1405
		$config = false;
1406
		// cache controll
1407
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1408
		if($oCacheHandler->isSupport())
1409
		{
1410
			$object_key = 'module_part_config:'.$module.'_'.$module_srl;
1411
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1412
			$config = $oCacheHandler->get($cache_key);
1413
		}
1414
1415
		if($config === false)
1416
		{
1417
			if(!isset($GLOBALS['__ModulePartConfig__'][$module][$module_srl]))
1418
			{
1419
				$args = new stdClass();
1420
				$args->module = $module;
1421
				$args->module_srl = $module_srl;
1422
				$output = executeQuery('module.getModulePartConfig', $args);
1423
				if($output->data->config) $config = unserialize($output->data->config);
1424
				else $config = null;
1425
1426
				//insert in cache
1427
				if($oCacheHandler->isSupport())
1428
				{
1429
					$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...
1430
				}
1431
				$GLOBALS['__ModulePartConfig__'][$module][$module_srl] = $config;
1432
			}
1433
			return $GLOBALS['__ModulePartConfig__'][$module][$module_srl];
1434
		}
1435
1436
		return $config;
1437
	}
1438
1439
	/**
1440
	 * @brief Get all of module configurations for each mid
1441
	 */
1442
	function getModulePartConfigs($module, $site_srl = 0)
1443
	{
1444
		$args = new stdClass();
1445
		$args->module = $module;
1446
		if($site_srl) $args->site_srl = $site_srl;
1447
		$output = executeQueryArray('module.getModulePartConfigs', $args);
1448
		if(!$output->toBool() || !$output->data) return array();
1449
1450
		foreach($output->data as $key => $val)
1451
		{
1452
			$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...
1453
		}
1454
		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...
1455
	}
1456
1457
	/**
1458
	 * @brief Get a list of module category
1459
	 */
1460
	function getModuleCategories($moduleCategorySrl = array())
1461
	{
1462
		$args = new stdClass();
1463
		$args->moduleCategorySrl = $moduleCategorySrl;
1464
		// Get data from the DB
1465
		$output = executeQuery('module.getModuleCategories', $args);
1466
		if(!$output->toBool()) return $output;
1467
		$list = $output->data;
1468
		if(!$list) return;
1469
		if(!is_array($list)) $list = array($list);
1470
1471
		foreach($list as $val)
1472
		{
1473
			$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...
1474
		}
1475
		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...
1476
	}
1477
1478
	/**
1479
	 * @brief Get content from the module category
1480
	 */
1481
	function getModuleCategory($module_category_srl)
1482
	{
1483
		// Get data from the DB
1484
		$args = new stdClass;
1485
		$args->module_category_srl = $module_category_srl;
1486
		$output = executeQuery('module.getModuleCategory', $args);
1487
		if(!$output->toBool()) return $output;
1488
		return $output->data;
1489
	}
1490
1491
	/**
1492
	 * @brief Get xml information of the module
1493
	 */
1494
	function getModulesXmlInfo()
1495
	{
1496
		// Get a list of downloaded and installed modules
1497
		$searched_list = FileHandler::readDir('./modules');
1498
		$searched_count = count($searched_list);
1499
		if(!$searched_count) return;
1500
		sort($searched_list);
1501
1502
		for($i=0;$i<$searched_count;$i++)
1503
		{
1504
			// Module name
1505
			$module_name = $searched_list[$i];
1506
1507
			$path = ModuleHandler::getModulePath($module_name);
1508
			// Get information of the module
1509
			$info = $this->getModuleInfoXml($module_name);
1510
			unset($obj);
1511
1512
			if(!isset($info)) continue;
1513
			$info->module = $module_name;
1514
			$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...
1515
			$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...
1516
			$info->path = $path;
1517
			$info->admin_index_act = $info->admin_index_act;
1518
			$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...
1519
		}
1520
		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...
1521
	}
1522
1523
	function checkNeedInstall($module_name)
1524
	{
1525
		$oDB = &DB::getInstance();
1526
		$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...
1527
1528
		$moduledir = ModuleHandler::getModulePath($module_name);
1529
		if(file_exists(FileHandler::getRealPath($moduledir."schemas")))
1530
		{
1531
			$tmp_files = FileHandler::readDir($moduledir."schemas", '/(\.xml)$/');
1532
			$table_count = count($tmp_files);
1533
			// Check if the table is created
1534
			$created_table_count = 0;
1535 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...
1536
			{
1537
				list($table_name) = explode(".",$tmp_files[$j]);
1538
				if($oDB->isTableExists($table_name)) $created_table_count ++;
1539
			}
1540
			// Check if DB is installed
1541
			if($table_count > $created_table_count) return true;
1542
			else return false;
1543
		}
1544
		return false;
1545
	}
1546
1547
	function checkNeedUpdate($module_name)
1548
	{
1549
		// Check if it is upgraded to module.class.php on each module
1550
		$oDummy = getModule($module_name, 'class');
1551
		if($oDummy && method_exists($oDummy, "checkUpdate"))
1552
		{
1553
			return $oDummy->checkUpdate();
1554
		}
1555
		return false;
1556
	}
1557
1558
	/**
1559
	 * @brief Get a type and information of the module
1560
	 */
1561
	function getModuleList()
1562
	{
1563
		// Create DB Object
1564
		$oDB = &DB::getInstance();
1565
		// Get a list of downloaded and installed modules
1566
		$searched_list = FileHandler::readDir('./modules', '/^([a-zA-Z0-9_-]+)$/');
1567
		sort($searched_list);
1568
1569
		$searched_count = count($searched_list);
1570
		if(!$searched_count) return;
1571
1572
		for($i=0;$i<$searched_count;$i++)
1573
		{
1574
			// module name
1575
			$module_name = $searched_list[$i];
1576
1577
			$path = ModuleHandler::getModulePath($module_name);
1578
			if(!is_dir(FileHandler::getRealPath($path))) continue;
1579
1580
			// Get the number of xml files to create a table in schemas
1581
			$tmp_files = FileHandler::readDir($path.'schemas', '/(\.xml)$/');
1582
			$table_count = count($tmp_files);
1583
			// Check if the table is created
1584
			$created_table_count = 0;
1585 View Code Duplication
			for($j=0;$j<$table_count;$j++)
1586
			{
1587
				list($table_name) = explode('.',$tmp_files[$j]);
1588
				if($oDB->isTableExists($table_name)) $created_table_count ++;
1589
			}
1590
			// Get information of the module
1591
			$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...
1592
			$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...
1593
1594
			if(!$info) continue;
1595
1596
			$info->module = $module_name;
1597
			$info->category = $info->category;
1598
			$info->created_table_count = $created_table_count;
1599
			$info->table_count = $table_count;
1600
			$info->path = $path;
1601
			$info->admin_index_act = $info->admin_index_act;
1602
			// Check if DB is installed
1603
			if($table_count > $created_table_count) $info->need_install = true;
1604
			else $info->need_install = false;
1605
			// Check if it is upgraded to module.class.php on each module
1606
			$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...
1607
			$oDummy = getModule($module_name, 'class');
1608
			if($oDummy && method_exists($oDummy, "checkUpdate"))
1609
			{
1610
				$info->need_update = $oDummy->checkUpdate();
1611
			}
1612
			else
1613
			{
1614
				continue;
1615
			}
1616
1617
			$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...
1618
		}
1619
		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...
1620
	}
1621
1622
	/**
1623
	 * @brief Combine module_srls with domain of sites
1624
	 * Because XE DBHandler doesn't support left outer join,
1625
	 * it should be as same as $Output->data[]->module_srl.
1626
	 */
1627
	function syncModuleToSite(&$data)
1628
	{
1629
		if(!$data) return;
1630
1631
		if(is_array($data))
1632
		{
1633
			foreach($data as $key => $val)
1634
			{
1635
				$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...
1636
			}
1637
			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...
1638
		}
1639
		else
1640
		{
1641
			$module_srls[] = $data->module_srl;
1642
		}
1643
1644
		$args = new stdClass();
1645
		$args->module_srls = implode(',',$module_srls);
1646
		$output = executeQueryArray('module.getModuleSites', $args);
1647
		if(!$output->data) return array();
1648
		foreach($output->data as $key => $val)
1649
		{
1650
			$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...
1651
		}
1652
1653
		if(is_array($data))
1654
		{
1655
			foreach($data as $key => $val)
1656
			{
1657
				$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...
1658
			}
1659
		}
1660
		else
1661
		{
1662
			$data->domain = $modules[$data->module_srl]->domain;
1663
		}
1664
	}
1665
1666
	/**
1667
	 * @brief Check if it is an administrator of site_module_info
1668
	 */
1669
	function isSiteAdmin($member_info, $site_srl = null)
1670
	{
1671
		if(!$member_info->member_srl) return false;
1672
		if($member_info->is_admin == 'Y') return true;
1673
1674
		$args = new stdClass();
1675 View Code Duplication
		if(!isset($site_srl))
1676
		{
1677
			$site_module_info = Context::get('site_module_info');
1678
			if(!$site_module_info) return;
1679
			$args->site_srl = $site_module_info->site_srl;
1680
		}
1681
		else
1682
		{
1683
			$args->site_srl = $site_srl;
1684
		}
1685
1686
		$args->member_srl = $member_info->member_srl;
1687
		$output = executeQuery('module.isSiteAdmin', $args);
1688
		if($output->data->member_srl == $args->member_srl) return true;
1689
		return false;
1690
	}
1691
1692
	/**
1693
	 * @brief Get admin information of the site
1694
	 */
1695
	function getSiteAdmin($site_srl)
1696
	{
1697
		$args = new stdClass;
1698
		$args->site_srl = $site_srl;
1699
		$output = executeQueryArray('module.getSiteAdmin', $args);
1700
		return $output->data;
1701
	}
1702
1703
	/**
1704
	 * @brief Get admin ID of the module
1705
	 */
1706
	function getAdminId($module_srl)
1707
	{
1708
		$obj = new stdClass();
1709
		$obj->module_srl = $module_srl;
1710
		$output = executeQueryArray('module.getAdminID', $obj);
1711
		if(!$output->toBool() || !$output->data) return;
1712
1713
		return $output->data;
1714
	}
1715
1716
	/**
1717
	 * @brief Get extra vars of the module
1718
	 * Extra information, not in the modules table
1719
	 */
1720
	function getModuleExtraVars($list_module_srl)
1721
	{
1722
		$extra_vars = array();
1723
		$get_module_srls = array();
1724
		if(!is_array($list_module_srl)) $list_module_srl = array($list_module_srl);
1725
1726
		$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...
1727
		// cache controll
1728
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1729
		if($oCacheHandler->isSupport())
1730
		{
1731
			foreach($list_module_srl as $module_srl)
1732
			{
1733
				$object_key = 'module_extra_vars:'.$module_srl;
1734
				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1735
				$vars = $oCacheHandler->get($cache_key);
1736
1737
				if($vars)
1738
				{
1739
					$extra_vars[$module_srl] = $vars;
1740
				}
1741
				else
1742
				{
1743
					$get_module_srls[] = $module_srl;
1744
				}
1745
			}
1746
		}
1747
		else
1748
		{
1749
			$get_module_srls = $list_module_srl;
1750
		}
1751
1752
		if(count($get_module_srls) > 0)
1753
		{
1754
			$args = new stdClass();
1755
			$args->module_srl = implode(',', $get_module_srls);
1756
			$output = executeQueryArray('module.getModuleExtraVars', $args);
1757
1758
			if(!$output->toBool())
1759
			{
1760
				return;
1761
			}
1762
1763
			if(!$output->data)
1764
			{
1765
				foreach($get_module_srls as $module_srl)
1766
				{
1767
					$extra_vars[$module_srl] = new stdClass;
1768
				}
1769
			}
1770
			foreach($output->data as $key => $val)
1771
			{
1772
				if(in_array($val->name, array('mid','module')) || $val->value == 'Array') continue;
1773
1774
				if(!isset($extra_vars[$val->module_srl]))
1775
				{
1776
					$extra_vars[$val->module_srl] = new stdClass();
1777
				}
1778
				$extra_vars[$val->module_srl]->{$val->name} = $val->value;
1779
1780 View Code Duplication
				if($oCacheHandler->isSupport())
1781
				{
1782
					$object_key = 'module_extra_vars:'.$val->module_srl;
1783
					$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1784
					$oCacheHandler->put($cache_key, $extra_vars[$val->module_srl]);
1785
				}
1786
			}
1787
		}
1788
1789
		return $extra_vars;
1790
	}
1791
1792
	/**
1793
	 * @brief Get skin information of the module
1794
	 */
1795 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...
1796
	{
1797
		$skin_vars = false;
1798
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1799
		if($oCacheHandler->isSupport())
1800
		{
1801
			$object_key = 'module_skin_vars:'.$module_srl;
1802
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1803
			$skin_vars = $oCacheHandler->get($cache_key);
1804
		}
1805
1806
		if($skin_vars === false)
1807
		{
1808
			$args = new stdClass();
1809
			$args->module_srl = $module_srl;
1810
			$output = executeQueryArray('module.getModuleSkinVars',$args);
1811
			if(!$output->toBool()) return;
1812
1813
			$skin_vars = array();
1814
			foreach($output->data as $vars)
1815
			{
1816
				$skin_vars[$vars->name] = $vars;
1817
			}
1818
1819
			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...
1820
		}
1821
1822
		return $skin_vars;
1823
	}
1824
1825
	/**
1826
	 * Get default skin name
1827
	 */
1828
	function getModuleDefaultSkin($module_name, $skin_type = 'P', $site_srl = 0, $updateCache = true)
1829
	{
1830
		$target = ($skin_type == 'M') ? 'mskin' : 'skin';
1831
		if(!$site_srl) $site_srl = 0;
1832
1833
		$designInfoFile = sprintf(_XE_PATH_.'files/site_design/design_%s.php', $site_srl);
1834
		if(is_readable($designInfoFile))
1835
		{
1836
			include($designInfoFile);
1837
1838
			$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...
1839
		}
1840
		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...
1841
		{
1842
			$dir = ($skin_type == 'M') ? 'm.skins/' : 'skins/';
1843
			$moduleSkinPath = ModuleHandler::getModulePath($module_name).$dir;
1844
1845
			if(is_dir($moduleSkinPath.'default'))
1846
			{
1847
				$skinName = 'default';
1848
			}
1849
			else if(is_dir($moduleSkinPath.'xe_default'))
1850
			{
1851
				$skinName = 'xe_default';
1852
			}
1853
			else
1854
			{
1855
				$skins = FileHandler::readDir($moduleSkinPath);
1856
				if(count($skins) > 0)
1857
				{
1858
					$skinName = $skins[0];
1859
				}
1860
				else
1861
				{
1862
					$skinName = NULL;
1863
				}
1864
			}
1865
1866
			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...
1867
			{
1868
				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...
1869
				$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...
1870
1871
				$oAdminController = getAdminController('admin');
1872
				$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...
1873
			}
1874
		}
1875
1876
		return $skinName;
1877
	}
1878
1879
	/**
1880
	 * @brief Combine skin information with module information
1881
	 */
1882
	function syncSkinInfoToModuleInfo(&$module_info)
1883
	{
1884
		if(!$module_info->module_srl) return;
1885
1886
		$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...
1887
		if(Mobile::isFromMobilePhone())
1888
		{
1889
			$skin_vars = $this->getModuleMobileSkinVars($module_info->module_srl);
1890
		}
1891
		else
1892
		{
1893
			$skin_vars = $this->getModuleSkinVars($module_info->module_srl);
1894
		}
1895
1896
		if(!$skin_vars) return;
1897
1898
		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...
1899
		{
1900
			if(isset($module_info->{$name})) continue;
1901
			$module_info->{$name} = $val->value;
1902
		}
1903
	}
1904
1905
	/**
1906
	 * Get mobile skin information of the module
1907
	 * @param $module_srl Sequence of module
1908
	 * @return array
1909
	 */
1910 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...
1911
	{
1912
		$skin_vars = false;
1913
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1914
		if($oCacheHandler->isSupport())
1915
		{
1916
			$object_key = 'module_mobile_skin_vars:'.$module_srl;
1917
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1918
			$skin_vars = $oCacheHandler->get($cache_key);
1919
		}
1920
1921
		if($skin_vars === false)
1922
		{
1923
			$args = new stdClass();
1924
			$args->module_srl = $module_srl;
1925
			$output = executeQueryArray('module.getModuleMobileSkinVars',$args);
1926
			if(!$output->toBool() || !$output->data) return;
1927
1928
			$skin_vars = array();
1929
			foreach($output->data as $vars)
1930
			{
1931
				$skin_vars[$vars->name] = $vars;
1932
			}
1933
1934
			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...
1935
		}
1936
1937
		return $skin_vars;
1938
	}
1939
1940
	/**
1941
	 * Combine skin information with module information
1942
	 * @param $module_info Module information
1943
	 */
1944
	function syncMobileSkinInfoToModuleInfo(&$module_info)
1945
	{
1946
		if(!$module_info->module_srl) return;
1947
		$skin_vars = false;
1948
		// cache controll
1949
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1950 View Code Duplication
		if($oCacheHandler->isSupport())
1951
		{
1952
			$object_key = 'module_mobile_skin_vars:'.$module_info->module_srl;
1953
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1954
			$skin_vars = $oCacheHandler->get($cache_key);
1955
		}
1956 View Code Duplication
		if($skin_vars === false)
1957
		{
1958
			$args = new stdClass;
1959
			$args->module_srl = $module_info->module_srl;
1960
			$output = executeQueryArray('module.getModuleMobileSkinVars',$args);
1961
			if(!$output->toBool()) return;
1962
			$skin_vars = $output->data;
1963
1964
			//insert in cache
1965
			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...
1966
		}
1967
		if(!$skin_vars) return;
1968
1969
		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...
1970
		{
1971
			if(isset($module_info->{$val->name})) continue;
1972
			$module_info->{$val->name} = $val->value;
1973
		}
1974
	}
1975
1976
	/**
1977
	 * @brief Return permission by using module info, xml info and member info
1978
	 */
1979
	function getGrant($module_info, $member_info, $xml_info = '')
1980
	{
1981
		$grant = new stdClass();
1982
1983
		if(!$xml_info)
1984
		{
1985
			$module = $module_info->module;
1986
			$xml_info = $this->getModuleActionXml($module);
1987
		}
1988
		// Set variables to grant group permission
1989
		$module_srl = $module_info->module_srl;
1990
		$grant_info = $xml_info->grant;
1991 View Code Duplication
		if($member_info->member_srl)
1992
		{
1993
			if(is_array($member_info->group_list)) $group_list = array_keys($member_info->group_list);
1994
			else $group_list = array();
1995
		}
1996
		else
1997
		{
1998
			$group_list = array();
1999
		}
2000
		// If module_srl doesn't exist(if unable to set permissions)
2001
		if(!$module_srl)
2002
		{
2003
			$grant->access = true;
2004
			if($this->isSiteAdmin($member_info, $module_info->site_srl))
2005
			{
2006
				$grant->access = $grant->manager = $grant->is_site_admin = true;
2007
			}
2008
2009
			$grant->is_admin = $grant->manager = ($member_info->is_admin == 'Y') ? true : false;
2010
		}
2011
		else
2012
		{
2013
			// If module_srl exists
2014
			// Get a type of granted permission
2015
			$grant->access = $grant->manager = $grant->is_site_admin = ($member_info->is_admin=='Y'||$this->isSiteAdmin($member_info, $module_info->site_srl))?true:false;
2016
			$grant->is_admin = ($member_info->is_admin == 'Y') ? true : false;
2017
			// If a just logged-in member is, check if the member is a module administrator
2018
			if(!$grant->manager && $member_info->member_srl)
2019
			{
2020
				$args = new stdClass();
2021
				$args->module_srl = $module_srl;
2022
				$args->member_srl = $member_info->member_srl;
2023
				$output = executeQuery('module.getModuleAdmin',$args);
2024
				if($output->data && $output->data->member_srl == $member_info->member_srl) $grant->manager = true;
2025
			}
2026
			// If not an administrator, get information from the DB and grant manager privilege.
2027
			if(!$grant->manager)
2028
			{
2029
				$args = new stdClass();
2030
				// If planet, get permission settings from the planet home
2031
				if($module_info->module == 'planet')
2032
				{
2033
					$output = executeQueryArray('module.getPlanetGrants', $args);
2034
				}
2035
				else
2036
				{
2037
					$args = new stdClass;
2038
					$args->module_srl = $module_srl;
2039
					$output = executeQueryArray('module.getModuleGrants', $args);
2040
				}
2041
2042
				$grant_exists = $granted = array();
2043
2044
				if($output->data)
2045
				{
2046
					// Arrange names and groups who has privileges
2047
					foreach($output->data as $val)
2048
					{
2049
						$grant_exists[$val->name] = true;
2050
						if($granted[$val->name]) continue;
2051
						// Log-in member only
2052
						if($val->group_srl == -1)
2053
						{
2054
							$granted[$val->name] = true;
2055
							if($member_info->member_srl) $grant->{$val->name} = true;
2056
							// Site-joined member only
2057
						}
2058
						elseif($val->group_srl == -2)
2059
						{
2060
							$granted[$val->name] = true;
2061
							// Do not grant any permission for non-logged member
2062
							if(!$member_info->member_srl) $grant->{$val->name} = false;
2063
							// Log-in member
2064
							else
2065
							{
2066
								$site_module_info = Context::get('site_module_info');
2067
								// Permission granted if no information of the currently connected site exists
2068
								if(!$site_module_info->site_srl) $grant->{$val->name} = true;
2069
								// Permission is not granted if information of the currently connected site exists
2070
								elseif(count($group_list)) $grant->{$val->name} = true;
2071
							}
2072
							// All of non-logged members
2073
						}
2074
						elseif($val->group_srl == 0)
2075
						{
2076
							$granted[$val->name] = true;
2077
							$grant->{$val->name} = true;
2078
							// If a target is a group
2079
						}
2080
						else
2081
						{
2082
							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...
2083
							{
2084
								$grant->{$val->name} = true;
2085
								$granted[$val->name] = true;
2086
							}
2087
						}
2088
					}
2089
				}
2090
				// Separate processing for the virtual group access
2091
				if(!$grant_exists['access']) $grant->access = true;
2092
				if(count($grant_info))
2093
				{
2094
					foreach($grant_info as  $grant_name => $grant_item)
2095
					{
2096
						if($grant_exists[$grant_name]) continue;
2097
						switch($grant_item->default)
2098
						{
2099
							case 'guest' :
2100
								$grant->{$grant_name} = true;
2101
								break;
2102
							case 'member' :
2103
								if($member_info->member_srl) $grant->{$grant_name} = true;
2104
								else $grant->{$grant_name} = false;
2105
								break;
2106
							case 'site' :
2107
								$site_module_info = Context::get('site_module_info');
2108
								if($member_info->member_srl && (($site_module_info->site_srl && count($group_list)) || !$site_module_info->site_srl)) $grant->{$grant_name} = true;
2109
								else $grant->{$grant_name} = false;
2110
								break;
2111
							case 'manager' :
2112
							case 'root' :
2113
								if($member_info->is_admin == 'Y') $grant->{$grant_name} = true;
2114
								else $grant->{$grant_name} = false;
2115
								break;
2116
						}
2117
					}
2118
				}
2119
			}
2120
			// Set true to grant all privileges if an administrator is
2121
			if($grant->manager)
2122
			{
2123
				$grant->access = true;
2124
				if(count($grant_info))
2125
				{
2126
					foreach($grant_info as $key => $val)
2127
					{
2128
						$grant->{$key} = true;
2129
					}
2130
				}
2131
			}
2132
		}
2133
		return $grant;
2134
	}
2135
2136
	function getModuleFileBox($module_filebox_srl)
2137
	{
2138
		$args = new stdClass();
2139
		$args->module_filebox_srl = $module_filebox_srl;
2140
		return executeQuery('module.getModuleFileBox', $args);
2141
	}
2142
2143
	function getModuleFileBoxList()
2144
	{
2145
		$oModuleModel = getModel('module');
2146
2147
		$args = new stdClass();
2148
		$args->page = Context::get('page');
2149
		$args->list_count = 5;
2150
		$args->page_count = 5;
2151
		$output = executeQuery('module.getModuleFileBoxList', $args);
2152
		$output = $oModuleModel->unserializeAttributes($output);
2153
		return $output;
2154
	}
2155
2156
	function unserializeAttributes($module_filebox_list)
2157
	{
2158
		if(is_array($module_filebox_list->data))
2159
		{
2160
			foreach($module_filebox_list->data as &$item)
2161
			{
2162
				if(empty($item->comment))
2163
				{
2164
					continue;
2165
				}
2166
2167
				$attributes = explode(';', $item->comment);
2168
				foreach($attributes as $attribute)
2169
				{
2170
					$values = explode(':', $attribute);
2171
					if((count($values) % 2) ==1)
2172
					{
2173
						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...
2174
						{
2175
							$values[1].=":".$values[$i];
2176
						}
2177
					}
2178
					$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...
2179
				}
2180
				$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...
2181
				unset($atts);
2182
			}
2183
		}
2184
		return $module_filebox_list;
2185
	}
2186
2187
	function getFileBoxListHtml()
2188
	{
2189
		$logged_info = Context::get('logged_info');
2190
		if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');
2191
		$link = parse_url($_SERVER["HTTP_REFERER"]);
2192
		$link_params = explode('&',$link['query']);
2193
		foreach ($link_params as $param)
2194
		{
2195
			$param = explode("=",$param);
2196
			if($param[0] == 'selected_widget') $selected_widget = $param[1];
2197
		}
2198
		$oWidgetModel = getModel('widget');
2199
		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...
2200
		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...
2201
2202
		$oModuleModel = getModel('module');
2203
		$output = $oModuleModel->getModuleFileBoxList();
2204
		Context::set('filebox_list', $output->data);
2205
2206
		$page = Context::get('page');
2207
		if (!$page) $page = 1;
2208
		Context::set('page', $page);
2209
		Context::set('page_navigation', $output->page_navigation);
2210
2211
		$security = new Security();
2212
		$security->encodeHTML('filebox_list..comment', 'filebox_list..attributes.');
2213
2214
		$oTemplate = &TemplateHandler::getInstance();
2215
		$html = $oTemplate->compile(_XE_PATH_ . 'modules/module/tpl/', 'filebox_list_html');
2216
2217
		$this->add('html', $html);
2218
	}
2219
2220
	function getModuleFileBoxPath($module_filebox_srl)
2221
	{
2222
		return sprintf("./files/attach/filebox/%s",getNumberingPath($module_filebox_srl,3));
2223
	}
2224
2225
	/**
2226
	 * @brief Return ruleset cache file path
2227
	 * @param module, act
2228
	 */
2229
	function getValidatorFilePath($module, $ruleset, $mid=null)
2230
	{
2231
		// load dynamic ruleset xml file
2232
		if(strpos($ruleset, '@') !== false)
2233
		{
2234
			$rulsetFile = str_replace('@', '', $ruleset);
2235
			$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile);
2236
			return FileHandler::getRealPath($xml_file);
2237
		}
2238
		else if (strpos($ruleset, '#') !== false)
2239
		{
2240
			$rulsetFile = str_replace('#', '', $ruleset).'.'.$mid;
2241
			$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile);
2242
			if(is_readable($xml_file))
2243
				return FileHandler::getRealPath($xml_file);
2244
			else{
2245
				$ruleset = str_replace('#', '', $ruleset);
2246
			}
2247
2248
		}
2249
		// Get a path of the requested module. Return if not exists.
2250
		$class_path = ModuleHandler::getModulePath($module);
2251
		if(!$class_path) return;
2252
2253
		// Check if module.xml exists in the path. Return if not exist
2254
		$xml_file = sprintf("%sruleset/%s.xml", $class_path, $ruleset);
2255
		if(!file_exists($xml_file)) return;
2256
2257
		return $xml_file;
2258
	}
2259
2260
	function getLangListByLangcodeForAutoComplete()
2261
	{
2262
		$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...
2263
2264
		$requestVars = Context::getRequestVars();
2265
2266
		$args = new stdClass;
2267
		$args->site_srl = (int)$requestVars->site_srl;
2268
		$args->page = 1; // /< Page
2269
		$args->list_count = 100; // /< the number of posts to display on a single page
2270
		$args->page_count = 5; // /< the number of pages that appear in the page navigation
2271
		$args->sort_index = 'name';
2272
		$args->order_type = 'asc';
2273
		$args->search_keyword = Context::get('search_keyword'); // /< keyword to search*/
2274
2275
		$output = executeQueryArray('module.getLangListByLangcode', $args);
2276
2277
		$list = array();
2278
2279
		if($output->toBool())
2280
		{
2281
			foreach((array)$output->data as $code_info)
2282
			{
2283
				unset($codeInfo);
2284
				$codeInfo = array('name'=>'$user_lang->'.$code_info->name, 'value'=>$code_info->value);
2285
				$list[] = $codeInfo;
2286
			}
2287
		}
2288
		$this->add('results', $list);
2289
	}
2290
2291
	/**
2292
	 * @brief already instance created module list
2293
	 */
2294
	function getModuleListByInstance($site_srl = 0, $columnList = array())
2295
	{
2296
		$args = new stdClass();
2297
		$args->site_srl = $site_srl;
2298
		$output = executeQueryArray('module.getModuleListByInstance', $args, $columnList);
2299
		return $output;
2300
	}
2301
2302
	function getLangByLangcode()
2303
	{
2304
		$langCode = Context::get('langCode');
2305
		if (!$langCode) return;
2306
2307
		$oModuleController = getController('module');
2308
		$oModuleController->replaceDefinedLangCode($langCode);
2309
2310
		$this->add('lang', $langCode);
2311
	}
2312
}
2313
/* End of file module.model.php */
2314
/* Location: ./modules/module/module.model.php */
2315