Completed
Push — master ( 4006e3...35fa08 )
by Flo
07:46
created

DbTables   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 37
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getTableData() 0 29 3
1
<?php
2
/**
3
 * Class DbTables | DbTables.php
4
 * @package Faulancer\Console\Helper
5
 * @author  Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\Console\Helper;
8
9
use Faulancer\Service\Config;
10
use ORM\DbConfig;
11
use ORM\EntityManager;
12
13
/**
14
 * Class DbTables
15
 */
16
class DbTables
17
{
18
19
    /**
20
     * @codeCoverageIgnore
21
     */
22
    public static function getTableData(Config $config)
23
    {
24
25
        $result = [];
26
27
        $dbConf = new DbConfig(
28
            $config->get('db:type'),
29
            $config->get('db:name'),
30
            $config->get('db:username'),
31
            $config->get('db:password'),
32
            $config->get('db:host')
33
        );
34
35
        $entityManager = new EntityManager([EntityManager::OPT_CONNECTION => $dbConf]);
36
        $tables        = $entityManager->getConnection()->query('SHOW TABLES')->fetchAll(\PDO::FETCH_UNIQUE);
37
38
        foreach (array_keys($tables) as $table) {
39
40
            $columns = $entityManager->getConnection()->query('SHOW COLUMNS FROM ' . $table)->fetchAll(\PDO::FETCH_ASSOC);
41
42
            foreach ($columns as $column) {
43
                $result[$table][] = $column;
44
            }
45
46
        }
47
48
        return $result;
49
50
    }
51
52
}