manager   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 60
ccs 23
cts 23
cp 1
rs 10
c 2
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_tools() 0 19 4
A __construct() 0 3 1
A get_tool() 0 12 3
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\trim;
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
	 */
23 43
	public function __construct($tools)
24
	{
25 43
		$this->tools = $tools;
26 43
	}
27
28
	/**
29
	 * Get all available tools
30
	 *
31
	 * @return array Array of available tools
32
	 */
33 38
	public function get_tools()
34
	{
35 38
		$tools = array();
36
37
		/** @var tools\tool_interface $tool */
38 38
		foreach ($this->tools as $tool)
39
		{
40 38
			if ($tool->is_available())
41 38
			{
42 38
				$tools[$tool->get_name()] = $tool;
43 38
			}
44 38
		}
45
46 38
		if (isset($tools['bbcodes']))
47 38
		{
48 13
			unset($tools['bbcodes_legacy']);
49 13
		}
50
51 38
		return $tools;
52
	}
53
54
	/**
55
	 * Get tool by name
56
	 *
57
	 * @param string $name Name of a trim tool service
58
	 *
59
	 * @return null|tools\tool_interface A trim tool object
60
	 */
61 5
	public function get_tool($name)
62
	{
63
		/** @var tools\tool_interface $tool */
64 5
		foreach ($this->tools as $tool)
65
		{
66 5
			if ($tool->get_name() === $name)
67 5
			{
68 1
				return $tool;
69
			}
70 4
		}
71
72 4
		return null;
73
	}
74
}
75