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.

Mysql::getListColumns()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 7

Duplication

Lines 19
Ratio 95 %

Importance

Changes 0
Metric Value
dl 19
loc 20
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Classes\AdaptersDriver;
4
5
use Classes\Db\Column;
6
use Classes\Db\Constrant;
7
use Classes\Db\DbTable;
8
9
require_once 'Classes/AdaptersDriver/AbsractAdapter.php';
10
require_once 'Classes/Db/Column.php';
11
require_once 'Classes/Db/Constrant.php';
12
require_once 'Classes/Db/DbTable.php';
13
14
/**
15
 * @author Pedro Alarcao <[email protected]>
16
 * @link   https://github.com/pedro151/orm-generator
17
 */
18
class Mysql extends AbsractAdapter
19
{
20
21
    /**
22
     * @var int
23
     */
24
    protected $port = 3306;
25
26
    /**
27
     * converts MySQL data types to Simple data types
28
     *
29
     * @param string $str
30
     *
31
     * @return string
32
     */
33
    protected function convertTypeToSimple ( $str )
34
    {
35
        $res = '';
36
        if ( preg_match ( '/(tinyint\(1\)|bit)/', $str ) ) {
37
            $res = 'boolean';
38
        }
39
        elseif ( preg_match ( '/(timestamp|blob|char|enum)/', $str ) ) {
40
            $res = 'string';
41
        }
42
        elseif ( preg_match ( '/(text)/', $str ) ) {
43
            $res = 'text';
44
        }
45
        elseif ( preg_match ( '/(decimal|numeric|float|double)/', $str ) ) {
46
            $res = 'float';
47
        }
48
        elseif ( preg_match ( '#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#', $str, $matches ) ) {
49
            $res = $matches[ 1 ];
50
        }
51
        elseif ( preg_match ( '/(date)/', $str ) ) {
52
            $res = 'date';
53
        }
54
        elseif ( preg_match ( '/(datetime)/', $str ) ) {
55
            $res = 'datetime';
56
        }
57
        else {
58
            print "Can't convert column type to Simple - Unrecognized type: $str";
59
        }
60
61
        return $res;
62
    }
63
64
    /**
65
     * @inheritDoc
66
     * @return string
67
     */
68
    public function getPDOString ()
69
    {
70
        return sprintf (
71
            "mysql:host=%s;port=%s;dbname=%s",
72
            $this->host,
73
            $this->port,
74
            $this->database
75
76
        );
77
    }
78
79
    /**
80
     * @inheritDoc
81
     * @return string
82
     */
83
    public function getPDOSocketString ()
84
    {
85
        return sprintf (
86
            "mysql:unix_socket=%s;dbname=%s",
87
            $this->socket,
88
            $this->database
89
90
        );
91
    }
92
93
    /**
94
     * @inheritDoc
95
     * @return string[]
96
     */
97
    public function getListNameTable ()
98
    {
99
        if ( empty( $this->tableList ) ) {
100
            $this->tableList = $this->getPDO ()
0 ignored issues
show
Bug introduced by
The property tableList does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
101
                                    ->query (
102
                                        "show tables"
103
                                    )
104
                                    ->fetchAll ();
105
        }
106
107
        return $this->tableList;
108
    }
109
110
    /**
111
     * retorna multiplos arrays com dados da column em array
112
     *
113
     * @return array[]
114
     */
115 View Code Duplication
    public function getListColumns ()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $sqlTables = !empty($this->tablesName)?"AND table_name IN ( $this->tablesName )":'';
118
119
        return $this->getPDO ()
120
                    ->query (
121
                        "select
122
                0 AS table_schema,
123
                table_name,
124
                column_name ,
125
                column_default,
126
                data_type,
127
                is_nullable,
128
                character_maximum_length AS max_length
129
            from information_schema.columns
130
            where table_schema IN ('{$this->database}') $sqlTables
131
            order by table_name,ordinal_position"
132
                    )
133
                    ->fetchAll ( \PDO::FETCH_ASSOC );
134
    }
135
136
    /**
137
     * @return array
138
     */
139 View Code Duplication
    public function getListConstrant ()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        $sqlTables = !empty($this->tablesName)?"AND k.table_name IN ( $this->tablesName )":'';
142
143
        $objQuery = $this->getPDO ()
144
                    ->query (
145
                        "SELECT distinct
146
     i.constraint_type,
147
     k.constraint_name,
148
     -- k.table_schema,
149
     0 AS table_schema,
150
     k.table_name,
151
	 k.column_name,
152
     -- k.REFERENCED_TABLE_SCHEMA AS foreign_schema,
153
     0 AS foreign_schema,
154
	 k.REFERENCED_TABLE_NAME AS foreign_table,
155
	 k.REFERENCED_COLUMN_NAME AS foreign_column
156
FROM information_schema.TABLE_CONSTRAINTS as i
157
inner join information_schema.key_column_usage as k
158
ON i.CONSTRAINT_NAME = k.CONSTRAINT_NAME and k.TABLE_SCHEMA <> 'mysql'
159
WHERE
160
i.TABLE_SCHEMA IN ('{$this->database}') AND i.CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY' ) $sqlTables
161
order by k.table_name;"
162
                    );
163
        return $objQuery?$objQuery->fetchAll ( \PDO::FETCH_ASSOC ):array();
164
    }
165
166
    /**
167
     * retorna o numero total de tabelas
168
     *
169
     * @return int
170
     */
171
    public function getTotalTables ()
172
    {
173
        if ( empty( $this->totalTables ) ) {
174
175
            $sqlTables = !empty($this->tablesName)?"AND table_name IN ( $this->tablesName )":'';
176
177
            $this->totalTables = $this->getPDO ()
178
                                      ->query (
179
                                          "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{$this->database}' $sqlTables"
180
                                      )
181
                                      ->fetchColumn ();
182
        }
183
184
        return (int) $this->totalTables;
185
    }
186
187
    /**
188
     * @inheritDoc
189
     *
190
     * @param $table
191
     * @param $column
192
     *
193
     * @return string
194
     */
195
    public function getSequence ( $table, $column, $schema = 0 )
196
    {
197
        $return = $this->getPDO ()
198
                       ->query (
199
                           "select * from information_schema.columns where extra like '%auto_increment%' and  TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';"
200
                       )
201
                       ->fetch ( \PDO::FETCH_ASSOC );
202
203
        if ( !$return ) {
204
            return;
205
        }
206
207
        return "{$return['TABLE_NAME']}_{$return['COLUMN_NAME']}_seq";
208
    }
209
210
}
211