Completed
Push — develop ( 613db1...73b4e9 )
by Daniel
05:02
created

blocks_factory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 56
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register_blocks() 0 8 2
A get() 0 4 2
A get_all() 0 12 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2018 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services\topic;
11
12
class blocks_factory
13
{
14
	/** @var array */
15
	private $blocks;
16
17
	/**
18
	 * Constructor
19
	 *
20
	 * @param \phpbb\di\service_collection			$blocks			Service Collection
21
	 */
22 3
	public function __construct(\phpbb\di\service_collection $blocks)
23
	{
24 3
		$this->register_blocks($blocks);
25 3
	}
26
27
	/**
28
	 * Register available topic blocks
29
	 * @param \phpbb\di\service_collection $blocks
30
	 */
31 3
	protected function register_blocks(\phpbb\di\service_collection $blocks)
32
	{
33 3
		$this->blocks = array();
34 3
		foreach ($blocks as $driver)
35
		{
36 3
			$this->blocks[$driver->get_name()] = $driver;
37 3
		}
38 3
	}
39
40
	/**
41
	 * Get topic block object
42
	 *
43
	 * @param string $service_name
44
	 * @return null|\blitze\content\services\topic\block_interface
45
	 */
46
	public function get($service_name)
47
	{
48
		return $this->blocks[$service_name] ?: null;
49
	}
50
51
	/**
52
	 * Get available content topic blocks
53
	 * @return array
54
	 */
55 2
	public function get_all()
56
	{
57 2
		$blocks = array();
58 2
		foreach ($this->blocks as $service => $driver)
59
		{
60 2
			$blocks[$service] = $driver->get_langname();
61 2
		}
62
63 2
		asort($blocks);
64
65 2
		return $blocks;
66
	}
67
}
68