Completed
Push — master ( 93a702...008e2c )
by Alexander
03:47
created

DriverFactoryRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 47
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 10 2
A get() 0 8 2
1
<?php
2
/**
3
 * This file is part of the phpunit-mink 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/aik099/phpunit-mink
9
 */
10
11
12
namespace aik099\PHPUnit\MinkDriver;
13
14
15
class DriverFactoryRegistry
16
{
17
18
	/**
19
	 * Driver factory registry.
20
	 *
21
	 * @var IMinkDriverFactory[]
22
	 */
23
	private $_registry = array();
24
25
	/**
26
	 * Registers Mink driver factory.
27
	 *
28
	 * @param IMinkDriverFactory $driver_factory Driver factory.
29
	 *
30
	 * @return void
31
	 * @throws \LogicException When driver factory is already registered.
32
	 */
33 12
	public function add(IMinkDriverFactory $driver_factory)
34
	{
35 12
		$driver_name = $driver_factory->getDriverName();
36
37 12
		if ( isset($this->_registry[$driver_name]) ) {
38 1
			throw new \LogicException('Driver factory for "' . $driver_name . '" driver is already registered.');
39
		}
40
41 12
		$this->_registry[$driver_name] = $driver_factory;
42 12
	}
43
44
	/**
45
	 * Looks up driver factory by name of the driver it can create.
46
	 *
47
	 * @param string $driver_name Driver name.
48
	 *
49
	 * @return IMinkDriverFactory
50
	 * @throws \OutOfBoundsException When driver not found.
51
	 */
52 15
	public function get($driver_name)
53
	{
54 15
		if ( !isset($this->_registry[$driver_name]) ) {
55 1
			throw new \OutOfBoundsException(sprintf('No driver factory for "%s" driver.', $driver_name));
56
		}
57
58 14
		return $this->_registry[$driver_name];
59
	}
60
61
}
62