helper::get_all_modules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
*
4
* @package Board3 Portal v2.1
5
* @copyright (c) 2014 Board3 Group ( www.board3.de )
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
namespace board3\portal\includes;
11
12
class helper
13
{
14
	/**
15
	* Board3 Modules service collection
16
	* @var \phpbb\di\service_collection
17
	*/
18
	protected $modules;
19
20
	/**
21
	* Constructor
22
	* NOTE: The parameters of this method must match in order and type with
23
	* the dependencies defined in the services.yml file for this service.
24
	* @param \phpbb\di\service_collection $modules Board3 Modules service
25
	*						collection
26
	*/
27 59
	public function __construct($modules)
28
	{
29 59
		$this->register_modules($modules);
30 59
	}
31
32
	/**
33
	* Register list of Board3 Portal modules
34
	*
35
	* @param \phpbb\di\service_collection $modules Board3 Modules service
36
	*						collection
37
	* @return null
38
	*/
39 59
	protected function register_modules($modules)
40
	{
41 59
		foreach ($modules as $current_module)
42
		{
43 59
			$class_name = '\\' . get_class($current_module);
44 59
			if (!isset($this->modules[$class_name]))
45 59
			{
46 59
				$this->modules[$class_name] = $current_module;
47 59
			}
48 59
		}
49 59
	}
50
51
	/**
52
	* Get module specified by module class name
53
	*
54
	* @param string $module_name Module class name
55
	*
56
	* @return bool|object The module object if it exists, false if not
57
	*/
58 26
	public function get_module($module_name)
59
	{
60 26
		if (isset($this->modules[$module_name]))
61 26
		{
62 22
			return $this->modules[$module_name];
63
		}
64
		else
65
		{
66 7
			return false;
67
		}
68
	}
69
70
	/**
71
	* Get all supported modules
72
	*
73
	* @return array An array containing all supported modules
74
	*/
75 1
	public function get_all_modules()
76
	{
77 1
		return $this->modules;
78
	}
79
}
80