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.

ModuleObject   F
last analyzed

Complexity

Total Complexity 95

Size/Duplication

Total Lines 482
Duplicated Lines 6.02 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 29
loc 482
rs 2
c 0
b 0
f 0
wmc 95
lcom 1
cbo 5

22 Methods

Rating   Name   Duplication   Size   Complexity  
A setModule() 0 4 1
A setModulePath() 0 8 2
A setRedirectUrl() 0 13 4
A getRedirectUrl() 0 4 1
A setMessage() 0 5 1
A setMessageType() 0 4 1
A getMessageType() 0 10 3
A setRefreshPage() 0 5 1
A setAct() 0 4 1
C setModuleInfo() 0 73 15
A stop() 0 19 2
A setTemplateFile() 0 8 3
A getTemplateFile() 0 4 1
B setTemplatePath() 15 15 7
A getTemplatePath() 0 4 1
A setEditedLayoutFile() 0 10 3
A getEditedLayoutFile() 0 4 1
A setLayoutFile() 0 10 3
A getLayoutFile() 0 4 1
B setLayoutPath() 14 14 7
A getLayoutPath() 0 4 1
F proc() 0 107 35

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ModuleObject often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ModuleObject, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* Copyright (C) XEHub <https://www.xehub.io> */
3
4
/**
5
 * @class ModuleObject
6
 * @author XEHub ([email protected])
7
 * base class of ModuleHandler
8
 * */
9
class ModuleObject extends BaseObject
10
{
11
12
	var $mid = NULL; ///< string to represent run-time instance of Module (XE Module)
13
	var $module = NULL; ///< Class name of Xe Module that is identified by mid
14
	var $module_srl = NULL; ///< integer value to represent a run-time instance of Module (XE Module)
15
	var $module_info = NULL; ///< an object containing the module information
16
	var $origin_module_info = NULL;
17
	var $xml_info = NULL; ///< an object containing the module description extracted from XML file
18
	var $module_path = NULL; ///< a path to directory where module source code resides
19
	var $act = NULL; ///< a string value to contain the action name
20
	var $template_path = NULL; ///< a path of directory where template files reside
21
	var $template_file = NULL; ///< name of template file
22
	var $layout_path = ''; ///< a path of directory where layout files reside
23
	var $layout_file = ''; ///< name of layout file
24
	var $edited_layout_file = ''; ///< name of temporary layout files that is modified in an admin mode
25
	var $stop_proc = FALSE; ///< a flag to indicating whether to stop the execution of code.
26
	var $module_config = NULL;
27
	var $ajaxRequestMethod = array('XMLRPC', 'JSON');
28
	var $gzhandler_enable = TRUE;
29
30
	/**
31
	 * setter to set the name of module
32
	 * @param string $module name of module
33
	 * @return void
34
	 * */
35
	function setModule($module)
36
	{
37
		$this->module = $module;
38
	}
39
40
	/**
41
	 * setter to set the name of module path
42
	 * @param string $path the directory path to a module directory
43
	 * @return void
44
	 * */
45
	function setModulePath($path)
46
	{
47
		if(substr_compare($path, '/', -1) !== 0)
48
		{
49
			$path.='/';
50
		}
51
		$this->module_path = $path;
52
	}
53
54
	/**
55
	 * setter to set an url for redirection
56
	 * @param string $url url for redirection
57
	 * @remark redirect_url is used only for ajax requests
58
	 * @return void
59
	 * */
60
	function setRedirectUrl($url = './', $output = NULL)
61
	{
62
		$ajaxRequestMethod = array_flip($this->ajaxRequestMethod);
63
		if(!isset($ajaxRequestMethod[Context::getRequestMethod()]))
64
		{
65
			$this->add('redirect_url', $url);
66
		}
67
68
		if($output !== NULL && is_object($output))
69
		{
70
			return $output;
71
		}
72
	}
73
74
	/**
75
	 * get url for redirection
76
	 * @return string redirect_url
77
	 * */
78
	function getRedirectUrl()
79
	{
80
		return $this->get('redirect_url');
81
	}
82
83
	/**
84
	 * set message
85
	 * @param string $message a message string
86
	 * @param string $type type of message (error, info, update)
87
	 * @return void
88
	 * */
89
	function setMessage($message = 'success', $type = NULL)
90
	{
91
		parent::setMessage($message);
92
		$this->setMessageType($type);
93
	}
94
95
	/**
96
	 * set type of message
97
	 * @param string $type type of message (error, info, update)
98
	 * @return void
99
	 * */
100
	function setMessageType($type)
101
	{
102
		$this->add('message_type', $type);
103
	}
104
105
	/**
106
	 * get type of message
107
	 * @return string $type
108
	 * */
109
	function getMessageType()
110
	{
111
		$type = $this->get('message_type');
112
		$typeList = array('error' => 1, 'info' => 1, 'update' => 1);
113
		if(!isset($typeList[$type]))
114
		{
115
			$type = $this->getError() ? 'error' : 'info';
116
		}
117
		return $type;
118
	}
119
120
	/**
121
	 * sett to set the template path for refresh.html
122
	 * refresh.html is executed as a result of method execution
123
	 * Tpl as the common run of the refresh.html ..
124
	 * @return void
125
	 * */
126
	function setRefreshPage()
127
	{
128
		$this->setTemplatePath('./common/tpl');
129
		$this->setTemplateFile('refresh');
130
	}
131
132
	/**
133
	 * sett to set the action name
134
	 * @param string $act
135
	 * @return void
136
	 * */
137
	function setAct($act)
138
	{
139
		$this->act = $act;
140
	}
141
142
	/**
143
	 * sett to set module information
144
	 * @param object $module_info object containing module information
145
	 * @param object $xml_info object containing module description
146
	 * @return void
147
	 * */
148
	function setModuleInfo($module_info, $xml_info)
149
	{
150
		// The default variable settings
151
		$this->mid = $module_info->mid;
152
		$this->module_srl = $module_info->module_srl;
153
		$this->module_info = $module_info;
154
		$this->origin_module_info = $module_info;
155
		$this->xml_info = $xml_info;
156
		$this->skin_vars = $module_info->skin_vars;
0 ignored issues
show
Bug introduced by
The property skin_vars does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
157
		// validate certificate info and permission settings necessary in Web-services
158
		$is_logged = Context::get('is_logged');
159
		$logged_info = Context::get('logged_info');
160
		// module model create an object
161
		$oModuleModel = getModel('module');
162
		// permission settings. access, manager(== is_admin) are fixed and privilege name in XE
163
		$module_srl = Context::get('module_srl');
164
		if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl))
165
		{
166
			$request_module = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
167
			if($request_module->module_srl == $module_srl)
168
			{
169
				$grant = $oModuleModel->getGrant($request_module, $logged_info);
170
			}
171
		}
172
		else
173
		{
174
			$grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info);
175
			// have at least access grant
176
			if(substr_count($this->act, 'Member') || substr_count($this->act, 'Communication'))
177
			{
178
				$grant->access = 1;
179
			}
180
		}
181
		// display no permission if the current module doesn't have an access privilege
182
		//if(!$grant->access) return $this->stop("msg_not_permitted");
183
		// checks permission and action if you don't have an admin privilege
184
		if(!$grant->manager)
0 ignored issues
show
Bug introduced by
The variable $grant 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...
185
		{
186
			// get permission types(guest, member, manager, root) of the currently requested action
187
			$permission_target = $xml_info->permission->{$this->act};
188
			// check manager if a permission in module.xml otherwise action if no permission
189
			if(!$permission_target && substr_count($this->act, 'Admin'))
190
			{
191
				$permission_target = 'manager';
192
			}
193
			// Check permissions
194
			switch($permission_target)
195
			{
196
				case 'root' :
197
				case 'manager' :
198
					$this->stop('msg_is_not_administrator');
199
					return;
200
				case 'member' :
201
					if(!$is_logged)
202
					{
203
						$this->stop('msg_not_permitted_act');
204
						return;
205
					}
206
					break;
207
			}
208
		}
209
		// permission variable settings
210
		$this->grant = $grant;
0 ignored issues
show
Bug introduced by
The property grant does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
211
212
		Context::set('grant', $grant);
213
214
		$this->module_config = $oModuleModel->getModuleConfig($this->module, $module_info->site_srl);
215
216
		if(method_exists($this, 'init'))
217
		{
218
			$this->init();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class ModuleObject as the method init() does only exist in the following sub-classes of ModuleObject: addonAdminController, addonAdminModel, addonAdminView, addonController, adminAdminController, adminAdminView, adminloggingController, autoinstallAdminController, autoinstallAdminView, boardAdminController, boardAdminModel, boardAdminView, boardController, boardMobile, boardModel, boardView, commentAdminController, commentAdminView, commentController, commentModel, commentView, communicationAdminController, communicationAdminModel, communicationAdminView, communicationController, communicationMobile, communicationModel, communicationView, counterAdminView, counterController, counterModel, documentAdminController, documentAdminModel, documentAdminView, documentController, documentModel, documentView, editorAdminController, editorAdminView, editorController, editorView, fileAdminController, fileAdminModel, fileAdminView, fileController, fileModel, fileView, importerAdminController, importerAdminView, installAdminController, installController, installView, integration_searchAdminController, integration_searchAdminView, integration_searchModel, integration_searchView, krzipAdminView, krzipView, layoutAdminController, layoutAdminModel, layoutAdminView, layoutModel, layoutView, memberAdminController, memberAdminModel, memberAdminView, memberController, memberMobile, memberModel, memberView, menuAdminController, menuAdminModel, menuAdminView, messageAdminController, messageAdminView, messageMobile, messageView, moduleAdminController, moduleAdminModel, moduleAdminView, moduleController, moduleModel, moduleView, pageAdminController, pageAdminView, pageController, pageMobile, pageView, pointAdminController, pointAdminView, pointController, pointModel, pointView, pollAdminController, pollAdminModel, pollAdminView, pollController, pollModel, rssAdminController, rssAdminView, rssController, rssView, seoAdminView, sessionAdminController, sessionAdminView, sessionController, sessionModel, spamfilterAdminController, spamfilterAdminView, spamfilterController, spamfilterModel, tagController, tagModel, trashAdminView, trashView, widgetAdminView, widgetController, widgetModel, widgetView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
219
		}
220
	}
221
222
	/**
223
	 * set the stop_proc and approprate message for msg_code
224
	 * @param string $msg_code an error code
225
	 * @return ModuleObject $this
226
	 * */
227
	function stop($msg_code)
228
	{
229
		// flag setting to stop the proc processing
230
		$this->stop_proc = TRUE;
231
		// Error handling
232
		$this->setError(-1);
233
		$this->setMessage($msg_code);
234
		// Error message display by message module
235
		$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
236
		$oMessageObject = ModuleHandler::getModuleInstance('message', $type);
237
		$oMessageObject->setError(-1);
238
		$oMessageObject->setMessage($msg_code);
239
		$oMessageObject->dispMessage();
240
241
		$this->setTemplatePath($oMessageObject->getTemplatePath());
242
		$this->setTemplateFile($oMessageObject->getTemplateFile());
243
244
		return $this;
245
	}
246
247
	/**
248
	 * set the file name of the template file
249
	 * @param string name of file
250
	 * @return void
251
	 * */
252
	function setTemplateFile($filename)
253
	{
254
		if(isset($filename) && substr_compare($filename, '.html', -5) !== 0)
255
		{
256
			$filename .= '.html';
257
		}
258
		$this->template_file = $filename;
259
	}
260
261
	/**
262
	 * retrieve the directory path of the template directory
263
	 * @return string
264
	 * */
265
	function getTemplateFile()
266
	{
267
		return $this->template_file;
268
	}
269
270
	/**
271
	 * set the directory path of the template directory
272
	 * @param string path of template directory.
273
	 * @return void
274
	 * */
275 View Code Duplication
	function setTemplatePath($path)
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...
276
	{
277
		if(!$path) return;
278
279
		if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
280
		{
281
			$path = './' . $path;
282
		}
283
284
		if(substr_compare($path, '/', -1) !== 0)
285
		{
286
			$path .= '/';
287
		}
288
		$this->template_path = $path;
289
	}
290
291
	/**
292
	 * retrieve the directory path of the template directory
293
	 * @return string
294
	 * */
295
	function getTemplatePath()
296
	{
297
		return $this->template_path;
298
	}
299
300
	/**
301
	 * set the file name of the temporarily modified by admin
302
	 * @param string name of file
303
	 * @return void
304
	 * */
305
	function setEditedLayoutFile($filename)
306
	{
307
		if(!$filename) return;
308
309
		if(substr_compare($filename, '.html', -5) !== 0)
310
		{
311
			$filename .= '.html';
312
		}
313
		$this->edited_layout_file = $filename;
314
	}
315
316
	/**
317
	 * retreived the file name of edited_layout_file
318
	 * @return string
319
	 * */
320
	function getEditedLayoutFile()
321
	{
322
		return $this->edited_layout_file;
323
	}
324
325
	/**
326
	 * set the file name of the layout file
327
	 * @param string name of file
328
	 * @return void
329
	 * */
330
	function setLayoutFile($filename)
331
	{
332
		if(!$filename) return;
333
334
		if(substr_compare($filename, '.html', -5) !== 0)
335
		{
336
			$filename .= '.html';
337
		}
338
		$this->layout_file = $filename;
339
	}
340
341
	/**
342
	 * get the file name of the layout file
343
	 * @return string
344
	 * */
345
	function getLayoutFile()
346
	{
347
		return $this->layout_file;
348
	}
349
350
	/**
351
	 * set the directory path of the layout directory
352
	 * @param string path of layout directory.
353
	 * */
354 View Code Duplication
	function setLayoutPath($path)
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...
355
	{
356
		if(!$path) return;
357
358
		if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
359
		{
360
			$path = './' . $path;
361
		}
362
		if(substr_compare($path, '/', -1) !== 0)
363
		{
364
			$path .= '/';
365
		}
366
		$this->layout_path = $path;
367
	}
368
369
	/**
370
	 * set the directory path of the layout directory
371
	 * @return string
372
	 * */
373
	function getLayoutPath($layout_name = "", $layout_type = "P")
374
	{
375
		return $this->layout_path;
376
	}
377
378
	/**
379
	 * excute the member method specified by $act variable
380
	 * @return boolean true : success false : fail
381
	 * */
382
	function proc()
383
	{
384
		// pass if stop_proc is true
385
		if($this->stop_proc)
386
		{
387
			debugPrint($this->message, 'ERROR');
0 ignored issues
show
Documentation introduced by
'ERROR' is of type string, but the function expects a boolean.

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...
388
			return FALSE;
389
		}
390
391
		// trigger call
392
		$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'before', $this);
393
		if(!$triggerOutput->toBool())
394
		{
395
			$this->setError($triggerOutput->getError());
396
			$this->setMessage($triggerOutput->getMessage());
397
			return FALSE;
398
		}
399
400
		// execute an addon(call called_position as before_module_proc)
401
		$called_position = 'before_module_proc';
402
		$oAddonController = getController('addon');
403
		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
404
		if(FileHandler::exists($addon_file)) include($addon_file);
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::exists($addon_file) of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
405
406
		if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act))
407
		{
408
			// Check permissions
409
			if($this->module_srl && !$this->grant->access)
410
			{
411
				$this->stop("msg_not_permitted_act");
412
				return FALSE;
413
			}
414
415
			// integrate skin information of the module(change to sync skin info with the target module only by seperating its table)
416
			$is_default_skin = ((!Mobile::isFromMobilePhone() && $this->module_info->is_skin_fix == 'N') || (Mobile::isFromMobilePhone() && $this->module_info->is_mskin_fix == 'N'));
417
			$usedSkinModule = !($this->module == 'page' && ($this->module_info->page_type == 'OUTSIDE' || $this->module_info->page_type == 'WIDGET'));
418
			if($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module)
419
			{
420
				$dir = (Mobile::isFromMobilePhone()) ? 'm.skins' : 'skins';
421
				$valueName = (Mobile::isFromMobilePhone()) ? 'mskin' : 'skin';
422
				$oModuleModel = getModel('module');
423
				$skinType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
424
				$skinName = $oModuleModel->getModuleDefaultSkin($this->module, $skinType);
425
				if($this->module == 'page')
426
				{
427
					$this->module_info->{$valueName} = $skinName;
428
				}
429
				else
430
				{
431
					$isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE);
432
					if(!$isTemplatPath)
433
					{
434
						$this->setTemplatePath(sprintf('%s%s/%s/', $this->module_path, $dir, $skinName));
435
					}
436
				}
437
			}
438
439
			$oModuleModel = getModel('module');
440
			$oModuleModel->syncSkinInfoToModuleInfo($this->module_info);
441
			Context::set('module_info', $this->module_info);
442
			// Run
443
			$output = $this->{$this->act}();
444
		}
445
		else
446
		{
447
			return FALSE;
448
		}
449
450
		// trigger call
451
		$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'after', $this);
452
		if(!$triggerOutput->toBool())
453
		{
454
			$this->setError($triggerOutput->getError());
455
			$this->setMessage($triggerOutput->getMessage());
456
			return FALSE;
457
		}
458
459
		// execute an addon(call called_position as after_module_proc)
460
		$called_position = 'after_module_proc';
461
		$oAddonController = getController('addon');
462
		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
463
		if(FileHandler::exists($addon_file)) include($addon_file);
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::exists($addon_file) of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
464
465
		if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject'))
466
		{
467
			$this->setError($output->getError());
468
			$this->setMessage($output->getMessage());
469
470
			if(!$output->toBool())
471
			{
472
				return FALSE;
473
			}
474
		}
475
		// execute api methods of the module if view action is and result is XMLRPC or JSON
476
		if($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile')
477
		{
478
			if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON')
479
			{
480
				$oAPI = getAPI($this->module_info->module, 'api');
0 ignored issues
show
Unused Code introduced by
The call to getAPI() has too many arguments starting with 'api'.

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...
481
				if(method_exists($oAPI, $this->act))
482
				{
483
					$oAPI->{$this->act}($this);
484
				}
485
			}
486
		}
487
		return TRUE;
488
	}
489
490
}
491
/* End of file ModuleObject.class.php */
492
/* Location: ./classes/module/ModuleObject.class.php */
493