GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SequelAdapter   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 28
c 0
b 0
f 0
dl 0
loc 73
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A showTables() 0 13 5
A showDatabases() 0 9 3
A showTablesFrom() 0 9 3
1
<?php
2
3
4
namespace Protoqol\Prequel\Classes\Database;
5
6
use Exception;
7
8
/**
9
 * Get queries based on chosen SQL driver.
10
 * Class SequelAdapter
11
 *
12
 * @package Protoqol\LaravelSequel\Classes\Database
13
 */
14
class SequelAdapter
15
{
16
17
    /**
18
     * Holds database type e.g. 'mysql', 'pgsql', 'sqlite' etc.
19
     *
20
     * @var string $databaseType
21
     */
22
    private $databaseType;
23
24
    /**
25
     * SequelAdapter constructor.
26
     *
27
     * @param  string  $databaseType
28
     */
29
    public function __construct(string $databaseType)
30
    {
31
        $this->databaseType = $databaseType;
32
    }
33
34
    /**
35
     * Get all tables
36
     *
37
     * @return string
38
     * @throws \Exception
39
     */
40
    public function showTables()
41
    {
42
        switch ($this->databaseType) {
43
            case 'mysql':
44
                return 'SHOW TABLES;';
45
            case 'pgsql':
46
                return 'SELECT * FROM pg_catalog.pg_tables;';
47
            case 'sqlite':
48
                return 'SELECT name FROM sqlite_master WHERE type="table";';
49
            case 'sqlsrv':
50
                return 'SELECT * FROM  INFORMATION_SCHEMA.TABLES; GO';
51
            default:
52
                throw new Exception('Selected invalid or unsupported database driver');
53
        }
54
    }
55
56
    /**
57
     * @return string
58
     * @throws \Exception
59
     */
60
    public function showDatabases()
61
    {
62
        switch ($this->databaseType) {
63
            case 'mysql':
64
                return 'SHOW DATABASES;';
65
            case 'pgsql':
66
                return 'SELECT datname FROM pg_database WHERE datistemplate = false;';
67
            default:
68
                throw new Exception('Selected invalid or unsupported database driver');
69
        }
70
    }
71
72
    /**
73
     * @param  string  $databaseName
74
     *
75
     * @return string
76
     * @throws \Exception
77
     */
78
    public function showTablesFrom(string $databaseName)
79
    {
80
        switch ($this->databaseType) {
81
            case 'mysql':
82
                return 'SHOW TABLES FROM `'.$databaseName.'`;';
83
            case 'pgsql':
84
                return 'SELECT * FROM pg_catalog.pg_tables;';
85
            default:
86
                throw new Exception('Selected invalid or unsupported database driver');
87
        }
88
    }
89
}
90