ReporterFactory::getNames()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of the Code-Insight library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight\BackwardsCompatibility\Reporter;
12
13
14
class ReporterFactory
15
{
16
17
	/**
18
	 * Backwards compatibility reporters.
19
	 *
20
	 * @var AbstractReporter[]
21
	 */
22
	protected $reporters = array();
23
24
	/**
25
	 * Adds backwards compatibility reporter.
26
	 *
27
	 * @param AbstractReporter $bc_reporter Backwards reporter reporter.
28
	 *
29
	 * @return void
30
	 * @throws \LogicException When backwards compatibility reporter is already added.
31
	 */
32
	public function add(AbstractReporter $bc_reporter)
33
	{
34
		$name = $bc_reporter->getName();
35
36
		if ( array_key_exists($name, $this->reporters) ) {
37
			throw new \LogicException(
38
				'The backwards compatibility reporter with "' . $name . '" name is already added.'
39
			);
40
		}
41
42
		$this->reporters[$name] = $bc_reporter;
43
	}
44
45
	/**
46
	 * Gets backwards compatibility reporter by name.
47
	 *
48
	 * @param string $name Backwards compatibility reporter name.
49
	 *
50
	 * @return AbstractReporter
51
	 * @throws \LogicException When Backwards compatibility reporter wasn't found.
52
	 */
53
	public function get($name)
54
	{
55
		if ( !array_key_exists($name, $this->reporters) ) {
56
			throw new \LogicException(
57
				'The backwards compatibility reporter with "' . $name . '" name is not found.'
58
			);
59
		}
60
61
		return $this->reporters[$name];
62
	}
63
64
	/**
65
	 * Returns possible reporters.
66
	 *
67
	 * @return array
68
	 */
69
	public function getNames()
70
	{
71
		return array_keys($this->reporters);
72
	}
73
74
}
75