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.
Passed
Push — master ( d395a9...487bee )
by Pedro
04:51 queued 02:06
created

Pgsql::getListColumns()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 8

Duplication

Lines 23
Ratio 95.83 %

Importance

Changes 0
Metric Value
dl 23
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 8
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 19 and the first side effect is on line 10.

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\AdapterConfig\AbstractAdapter;
6
use Classes\Db\Column;
7
use Classes\Db\Constrant;
8
use Classes\Db\DbTable;
9
10
require_once 'Classes/AdaptersDriver/AbsractAdapter.php';
11
require_once 'Classes/Db/Column.php';
12
require_once 'Classes/Db/Constrant.php';
13
require_once 'Classes/Db/DbTable.php';
14
15
/**
16
 * @author Pedro Alarcao <[email protected]>
17
 * @link   https://github.com/pedro151/orm-generator
18
 */
19
class Pgsql extends AbsractAdapter
20
{
21
22
    /**
23
     * @var int
24
     */
25
    protected $port = 5432;
26
27
    /**
28
     * @type array|\string[]
29
     */
30
    protected $schema = array ( 'public' );
31
32
    protected $dataTypesToSimple = array (
33
        /* Numeric Types */
34
        'smallint'         => 'int',
35
        'integer'          => 'int',
36
        'serial'           => 'int',
37
        'bigint'           => 'float',
38
        'decimal'          => 'float',
39
        'numeric'          => 'float',
40
        'real'             => 'float',
41
        'double precision' => 'float',
42
        'bigserial'        => 'float',
43
        /* Monetary Types */
44
        'money'            => 'float',
45
        /* Binary Data Types */
46
        'bytea'            => 'int',
47
        /* Character Types */
48
        'character varyin' => 'string',
49
        'varchar'          => 'string',
50
        'character'        => 'string',
51
        'char'             => 'string',
52
        'text'             => 'text',
53
        /* Date/Time Types */
54
        'datetime'         => 'datetime',
55
        'timestamp without time zone' => 'timestamp',
56
        'date'             => 'date',
57
        /* Boolean Type */
58
        'boolean'          => 'boolean'
59
    );
60
61
    public function __construct ( AbstractAdapter $adapterConfig )
62
    {
63
        parent::__construct ( $adapterConfig );
64
        if ( $adapterConfig->hasSchemas () ) {
65
            $this->schema = $adapterConfig->getSchemas ();
66
        }
67
68
    }
69
70
    /**
71
     * Retorna um Array com nome das tabelas
72
     *
73
     * @param void $schema
0 ignored issues
show
Bug introduced by
There is no parameter named $schema. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
     *
75
     * @return string[]
76
     */
77 View Code Duplication
    public function getListNameTable ()
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...
78
    {
79
        if ( empty( $this->tableList ) ) {
80
81
            $sqlTables = !empty($this->tablesName)?"AND table_name IN ( $this->tablesName )":'';
82
83
            $strSchema = implode ( "', '", $this->schema );
84
85
            $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...
86
                                    ->query (
87
                                        "SELECT table_schema,
88
              table_name
89
             FROM information_schema.tables
90
             WHERE
91
              table_type = 'BASE TABLE'
92
              AND table_schema IN ( '$strSchema' ) $sqlTables
93
              ORDER by
94
               table_schema,
95
               table_name
96
              ASC"
97
                                    )
98
                                    ->fetchAll ();
99
        }
100
101
        return $this->tableList;
102
    }
103
104
    /**
105
     * retorna multiplos arrays com dados da column em array
106
     *
107
     * @return array
108
     */
109 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...
110
    {
111
        $sqlTables = !empty($this->tablesName)?"AND c.table_name IN ( $this->tablesName )":'';
112
        $strSchema = implode ( "', '", $this->schema );
113
114
        return $this->getPDO ()
115
                    ->query (
116
                        "SELECT distinct
117
	c.table_schema,
118
	c.table_name,
119
	c.column_name ,
120
	c.data_type,
121
	c.column_default,
122
	is_nullable,
123
	character_maximum_length AS max_length
124
		FROM
125
		information_schema.tables AS st
126
		INNER JOIN  information_schema.columns AS c
127
		ON st.table_name=c.table_name and st.table_type = 'BASE TABLE'
128
		 $sqlTables and  c.table_schema IN ('$strSchema')
129
		order by c.table_name asc"
130
                    )
131
                    ->fetchAll ( \PDO::FETCH_ASSOC );
132
    }
133
134 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...
135
    {
136
        $sqlTables = !empty($this->tablesName)?"AND tc.table_name IN ( $this->tablesName )":'';
137
        $strSchema = implode ( "', '", $this->schema );
138
139
        return $this->getPDO ()
140
                    ->query (
141
                        "SELECT distinct
142
                tc.constraint_type,
143
                tc.constraint_name,
144
                tc.table_schema,
145
                tc.table_name,
146
                kcu.column_name,
147
		        ccu.table_schema AS foreign_schema,
148
                ccu.table_name AS foreign_table,
149
                ccu.column_name as foreign_column
150
                  FROM
151
                information_schema.table_constraints AS tc
152
                    JOIN information_schema.key_column_usage AS kcu
153
                      ON tc.constraint_name = kcu.constraint_name
154
                       AND tc.table_schema IN ('$strSchema')
155
                       AND tc.constraint_type IN ('FOREIGN KEY','PRIMARY KEY')
156
                       $sqlTables
157
                    JOIN information_schema.constraint_column_usage AS ccu
158
                      ON tc.constraint_name  = ccu.constraint_name
159
                        AND tc.constraint_schema = ccu.constraint_schema
160
                    ORDER by tc.table_schema"
161
                    )
162
                    ->fetchAll ( \PDO::FETCH_ASSOC );
163
    }
164
165
    /**
166
     * Retorna o Nome da Sequence da tabela
167
     *
168
     * @param $table
169
     * @param $column
170
     *
171
     * @return string
172
     */
173
    public function getSequence ( $table, $column, $schema = 0 )
174
    {
175
        $tableTemp = $table;
176
        if ( 0 !== $schema ) {
177
            $tableTemp = $schema . '.' . $table;
178
        }
179
180
        $pdo     = $this->getPDO ();
181
        $return1 = $pdo->query ( "SELECT pg_get_serial_sequence('$tableTemp', '$column');" )
182
                       ->fetchColumn ();
183
184
        if ( !is_null ( $return1 ) ) {
185
            return $return1;
186
        }
187
188
        $stmt = $pdo->prepare (
189
            "SELECT distinct adsrc FROM pg_attrdef AS att
190
            INNER JOIN pg_class AS c
191
              ON adrelid = c.oid AND c.relname = ? --table
192
            INNER JOIN pg_attribute AS a
193
              ON att.adnum=a.attnum AND a.attname=? --column
194
            INNER JOIN pg_catalog.pg_namespace n
195
              ON n.oid = c.relnamespace and n.nspname=? --schema
196
              "
197
        );
198
199
        $stmt->bindParam ( 1, $table );
200
        $stmt->bindParam ( 2, $column );
201
        $stmt->bindParam ( 3, $schema );
202
        $stmt->execute ();
203
        $return2 = $stmt->fetchColumn ();
204
205
        if ( $return2 ) {
206
            return preg_filter (
207
                array (
208
                    '/nextval\(\'/',
209
                    '/\'::regclass\)/'
210
                ),
211
                '',
212
                $return2
213
            );
214
        }
215
216
    }
217
218
    /**
219
     * @inheritDoc
220
     * @return string
221
     */
222
    public function getPDOString ()
223
    {
224
        return sprintf (
225
            "pgsql:host=%s;port=%s;dbname=%s",
226
            $this->host,
227
            $this->port,
228
            $this->database
229
230
        );
231
    }
232
233
    /**
234
     * @inheritDoc
235
     * @return string
236
     */
237
    public function getPDOSocketString ()
238
    {
239
        return sprintf (
240
            "pgsql:unix_socket=%s;dbname=%s",
241
            $this->socket,
242
            $this->database
243
244
        );
245
    }
246
247
    /**
248
     * retorna o numero total de tabelas
249
     *
250
     * @return int
251
     */
252 View Code Duplication
    public function getTotalTables ()
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...
253
    {
254
        if ( empty( $this->totalTables ) ) {
255
            $sqlTables = !empty($this->tablesName)?"AND table_name IN ( $this->tablesName )":'';
256
257
            $strSchema = implode ( "', '", $this->schema );
258
259
            $this->totalTables = $this->getPDO ()
260
                                      ->query (
261
                                          "SELECT COUNT(table_name)  AS total
262
             FROM information_schema.tables
263
             WHERE
264
              table_type = 'BASE TABLE'
265
              AND table_schema IN ( '" . $strSchema . "' ) $sqlTables"
266
                                      )
267
                                      ->fetchColumn ();
268
        }
269
270
        return (int) $this->totalTables;
271
    }
272
}
273