Passed
Push — master ( 78ff77...606203 )
by Aimeos
04:53
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 5
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 * @package MW
8
 * @subpackage DB
9
 */
10
11
12
namespace Aimeos\Base\DB;
13
14
15
/**
16
 * Creates new database manager instances.
17
 *
18
 * @package MW
19
 * @subpackage DB
20
 */
21
class Factory
22
{
23
	/**
24
	 * Creates and returns a database manager.
25
	 *
26
	 * @param \Aimeos\Base\Config\Iface $config Configuration class instance
27
	 * @param string $type Name of the manager
28
	 * @return \Aimeos\Base\DB\Manager\Iface Instance of a database manager
29
	 * @throws \Aimeos\Base\DB\Exception if database manager class isn't found
30
	 */
31
	public static function create( \Aimeos\Base\Config\Iface $config, $type = 'PDO' )
32
	{
33
		$classname = '\Aimeos\Base\DB\Manager\\' . $type;
34
35
		if( !class_exists( $classname ) ) {
36
			throw new \Aimeos\Base\DB\Exception( sprintf( 'File system "%1$s" not found', $type ) );
37
		}
38
39
		return new $classname( $config );
40
	}
41
}
42