Passed
Pull Request — development (#3621)
by Emanuele
07:11
created

AbstractModule::setEventManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * Abstract for modules.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * @version 2.0 dev
11
 *
12
 */
13
14
namespace ElkArte\Modules;
15
16
use ElkArte\HttpReq;
17
use ElkArte\UserInfo;
18
use ElkArte\EventManager;
19
20
/**
21
 * Abstract AbstractModule Provides some standard values to modules
22
 *
23
 * @package ElkArte\sources\modules
24
 */
25
abstract class AbstractModule implements ModuleInterface
26
{
27
	/** @var \ElkArte\HttpReq|null Access to post/get data */
28
	protected $_req;
29
30
	/** @var \ElkArte\UserInfo|null User Info ValuesContainer */
31
	protected $user;
32
33
	/** @var \ElkArte\EventManager|null Events for all our fans! */
34
	protected $event;
35
36
	/**
37
	 * AbstractModule constructor.
38
	 *
39
	 * @param \ElkArte\HttpReq $req
40
	 * @param \ElkArte\UserInfo $user
41
	 */
42
	public function __construct(HttpReq $req, UserInfo $user)
43
	{
44
		$this->_req = $req;
45
		$this->user = $user;
46
	}
47
48
	/**
49
	 * Sets the event manager.
50
	 *
51
	 * @param \ElkArte\EventManager $event
52
	 */
53
	public function setEventManager(EventManager $event)
54
	{
55
		$this->event = $event;
56
	}
57
58
	/**
59
	 * Helper function to see if a request is asking for any api processing
60
	 *
61
	 * @return string|false
62
	 */
63
	public function getApi()
64
	{
65
		// API Call?
66
		$api = $this->_req->getRequest('api', 'trim', '');
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
		/** @scrutinizer ignore-call */ 
67
  $api = $this->_req->getRequest('api', 'trim', '');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
		return in_array($api, ['xml', 'json', 'html']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) ? $api : false;
69
	}
70
}
71