blocks_factory::get_all()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 10
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\driver\block_interface
45
	 */
46
	public function get($service_name)
47
	{
48
		return isset($this->blocks[$service_name]) ? $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