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

DriverFactoryRegistry::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 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