Failed Conditions
Push — master ( a2f8a2...e02dc1 )
by Alexander
01:53
created

CheckerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 51
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 12 2
A get() 0 10 2
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;
12
13
14
class CheckerFactory
15
{
16
17
	/**
18
	 * Backwards compatibility checkers.
19
	 *
20
	 * @var AbstractChecker[]
21
	 */
22
	protected $checkers = array();
23
24
	/**
25
	 * Adds backwards compatibility checker.
26
	 *
27
	 * @param AbstractChecker $bc_checker Backwards compatibility checker.
28
	 *
29
	 * @return void
30
	 * @throws \LogicException When backwards compatibility checker is already added.
31
	 */
32
	public function add(AbstractChecker $bc_checker)
33
	{
34
		$name = $bc_checker->getName();
35
36
		if ( array_key_exists($name, $this->checkers) ) {
37
			throw new \LogicException(
38
				'The backwards compatibility checker with "' . $name . '" name is already added.'
39
			);
40
		}
41
42
		$this->checkers[$name] = $bc_checker;
43
	}
44
45
	/**
46
	 * Gets backwards compatibility checker by name.
47
	 *
48
	 * @param string $name Backwards compatibility checker name.
49
	 *
50
	 * @return AbstractChecker
51
	 * @throws \LogicException When Backwards compatibility checker wasn't found.
52
	 */
53
	public function get($name)
54
	{
55
		if ( !array_key_exists($name, $this->checkers) ) {
56
			throw new \LogicException(
57
				'The backwards compatibility checker with "' . $name . '" name is not found.'
58
			);
59
		}
60
61
		return $this->checkers[$name];
62
	}
63
64
}
65