DatabaseFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 19
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Zortje\MySQLKeeper;
4
5
use Zortje\MySQLKeeper\Database\TableCollection;
6
use Zortje\MySQLKeeper\Database\TableFactory;
7
8
/**
9
 * Class DatabaseFactory
10
 *
11
 * @package Zortje\MySQLKeeper
12
 */
13
class DatabaseFactory {
14
15
	/**
16
	 * Create database
17
	 *
18
	 * @param \PDO $pdo Database connection
19
	 *
20
	 * @return Database
21
	 */
22 2
	public static function create(\PDO $pdo) {
23
		/**
24
		 * Tables
25
		 */
26 2
		$tables = new TableCollection();
27
28 2
		foreach ($pdo->query('SHOW TABLES;') as $row) {
29 2
			$table = TableFactory::create($row[0], $pdo);
30
31 2
			$tables->add($table);
32 2
		}
33
34
		/**
35
		 * Initialization
36
		 */
37 2
		$database = new Database($tables);
38
39 2
		return $database;
40
	}
41
}
42