Completed
Pull Request — master (#28)
by Matt
02:49
created

manager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * Topic Preview
5
 *
6
 * @copyright (c) 2016 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\topicpreview\core\tools;
12
13
class manager
14
{
15
	/** @var array Array of tools from the service collection */
16
	protected $tools = array();
17
18
	/**
19
	 * Constructor
20
	 *
21
	 * @param array $tools Array of tools from the service collection
22
	 * @access public
23
	 */
24
	public function __construct($tools)
25
	{
26
		$this->tools = $tools;
27
	}
28
29
	/**
30
	 * Get all available tools
31
	 *
32
	 * @return array Array of available tools
33
	 */
34
	public function get_tools()
35
	{
36
		$tools = array();
37
38
		/** @var tool_interface $tool */
39
		foreach ($this->tools as $tool)
40
		{
41
			if ($tool->is_available())
42
			{
43
				$tools[$tool->get_name()] = $tool;
44
			}
45
		}
46
47
		if (isset($tools['remove_bbcodes']))
48
		{
49
			unset($tools['remove_bbcodes_legacy']);
50
		}
51
52
		return $tools;
53
	}
54
55
	/**
56
	 * Get tool by name
57
	 *
58
	 * @param string $name
59
	 * @return null|tool_interface
60
	 */
61
	public function get_tool($name)
62
	{
63
		/** @var tool_interface $tool */
64
		foreach ($this->tools as $tool)
65
		{
66
			if ($tool->get_name() == $name)
67
			{
68
				return $tool;
69
			}
70
		}
71
72
		return null;
73
	}
74
}
75