Completed
Push — master ( 7d4e77...353440 )
by Matt
08:22
created

manager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 78
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get_all_locations() 0 14 2
A register_template_locations() 0 10 3
A get_all_location_ids() 0 14 3
A __construct() 0 4 1
1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\admanagement\location;
12
13
class manager
14
{
15
	/**
16
	* Array that contains all available template location types which are passed
17
	* via the service container
18
	* @var array
19
	*/
20
	protected $template_locations;
21
22
	/**
23
	* Construct an template locations manager object
24
	*
25
	* @param	array	$template_locations	Template location types passed via the service container
26
	*/
27 32
	public function __construct($template_locations)
28 1
	{
29 32
		$this->register_template_locations($template_locations);
30 32
	}
31
32
	/**
33
	* Get a list of all template location types
34
	*
35
	* Returns an associated array where key is the location id
36
	* and value is array of location name and location description.
37
	*
38
	* @return	array	Array containing a list of all template locations
39
	*/
40 10
	public function get_all_locations()
41
	{
42 10
		$location_types = array();
43
44 10
		foreach ($this->template_locations as $id => $location_type)
45
		{
46 10
			$location_types[$id] = array(
47 10
				'name'	=> $location_type->get_name(),
48 10
				'desc'	=> $location_type->get_desc(),
49
			);
50 10
		}
51
52 10
		return $location_types;
53
	}
54
55
	/**
56
	* Get a list of all template location IDs for display
57
	*
58
	* @return	array	Array containing a list of all template location IDs
59
	*/
60 1
	public function get_all_location_ids()
61
	{
62 1
		$template_locations = array();
63
64 1
		foreach ($this->template_locations as $location_id => $location)
65
		{
66 1
			if ($location->will_display())
67 1
			{
68 1
				$template_locations[] = $location_id;
69 1
			}
70 1
		}
71
72 1
		return $template_locations;
73
	}
74
75
	/**
76
	* Register template locations
77
	*
78
	* @param	array	$template_locations	Template location types passed via the service container
79
	*/
80 32
	protected function register_template_locations($template_locations)
81
	{
82 32
		if (!empty($template_locations))
83 32
		{
84 32
			foreach ($template_locations as $location)
85
			{
86 32
				$this->template_locations[$location->get_id()] = $location;
87 32
			}
88 32
		}
89 32
	}
90
}
91