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.
Completed
Push — master ( da0c0a...d8b20a )
by Pedro
03:21
created

Mysql::getPDOSocketString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 3 Features 0
Metric Value
c 5
b 3
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
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 PHP data types
28
     *
29
     * @param string $str
30
     *
31
     * @return string
32
     */
33
    protected function convertTypeToPhp ( $str )
34
    {
35
        $res = '';
36
        if ( preg_match ( '/(tinyint\(1\)|bit)/' , $str ) )
37
        {
38
            $res = 'boolean';
39
        } elseif ( preg_match ( '/(datetime|timestamp|blob|char|enum|text|date)/' , $str ) )
40
        {
41
            $res = 'string';
42
        } elseif ( preg_match ( '/(decimal|numeric|float|double)/' , $str ) )
43
        {
44
            $res = 'float';
45
        } elseif ( preg_match ( '#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#' , $str , $matches ) )
46
        {
47
            $res = $matches[ 1 ];
48
        } else
49
        {
50
            print "Can't convert column type to PHP - Unrecognized type: $str";
51
        }
52
53
        return $res;
54
    }
55
56
    /**
57
     * @inheritDoc
58
     * @return string
59
     */
60
    public function getPDOString ()
61
    {
62
        return sprintf (
63
            "mysql:host=%s;port=%s;dbname=%s" ,
64
            $this->host ,
65
            $this->port ,
66
            $this->database
67
68
        );
69
    }
70
71
    /**
72
     * @inheritDoc
73
     * @return string
74
     */
75
    public function getPDOSocketString ()
76
    {
77
        return sprintf (
78
            "mysql:unix_socket=%s;dbname=%s" ,
79
            $this->socket ,
80
            $this->database
81
82
        );
83
    }
84
85
    /**
86
     * @inheritDoc
87
     * @return string[]
88
     */
89
    public function getListNameTable ()
90
    {
91
        if ( empty( $this->tableList ) )
92
        {
93
            $this->tableList = $this->getPDO ()->query (
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...
94
                "show tables"
95
            )->fetchAll ();
96
        }
97
98
        return $this->tableList;
99
    }
100
101
    /**
102
     * retorna multiplos arrays com dados da column em array
103
     *
104
     * @return array[]
105
     */
106
    public function getListColumns ()
107
    {
108
109
        return $this->getPDO ()->query (
110
            "select
111
                0 AS table_schema,
112
                table_name,
113
                column_name ,
114
                data_type,
115
                is_nullable,
116
                character_maximum_length AS max_length
117
            from information_schema.columns
118
            where table_schema IN ('{$this->database}')
119
            order by table_name,ordinal_position"
120
        )->fetchAll ( \PDO::FETCH_ASSOC );
121
    }
122
123
    /**
124
     * @return array
125
     */
126
    public function getListConstrant ()
127
    {
128
        return $this->getPDO ()->query (
129
            "SELECT distinct
130
     i.constraint_type,
131
     k.constraint_name,
132
     --k.table_schema,
133
     0 AS table_schema,
134
     k.table_name,
135
	 k.column_name,
136
     k.REFERENCED_TABLE_SCHEMA AS foreign_schema,
137
	 k.REFERENCED_TABLE_NAME AS foreign_table,
138
	 k.REFERENCED_COLUMN_NAME AS foreign_column
139
FROM information_schema.TABLE_CONSTRAINTS as i
140
inner join information_schema.key_column_usage as k
141
ON i.CONSTRAINT_NAME = k.CONSTRAINT_NAME and k.TABLE_SCHEMA <> 'mysql'
142
WHERE
143
i.TABLE_SCHEMA IN ('{$this->database}') AND i.CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY' )
144
order by k.table_schema, k.table_name;"
145
        )->fetchAll ( \PDO::FETCH_ASSOC );
146
    }
147
148
    /**
149
     * retorna o numero total de tabelas
150
     *
151
     * @return int
152
     */
153
    public function getTotalTables ()
154
    {
155
        if ( empty( $this->totalTables ) )
156
        {
157
158
            $this->totalTables = $this->getPDO ()->query (
159
                "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{$this->database}'"
160
            )->fetchColumn ();
161
        }
162
163
        return (int) $this->totalTables;
164
    }
165
166
    /**
167
     * @inheritDoc
168
     *
169
     * @param $table
170
     * @param $column
171
     *
172
     * @return string
173
     */
174
    public function getSequence ( $table , $column )
175
    {
176
        $return = $this->getPDO ()
177
                       ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and  TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" )
178
                       ->fetch ( \PDO::FETCH_ASSOC );
179
180
        if ( ! $return )
181
        {
182
            return;
183
        }
184
185
        return "{$return['TABLE_NAME']}_{$return['COLUMN_NAME']}_seq";
186
    }
187
188
}
189