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.

Mssql::getHost()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
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 Mssql extends AbsractAdapter
20
{
21
22
    /**
23
     * @var int
24
     */
25
    protected $port;
26
27
    protected $schema = array ( 'public' );
28
29
    public function __construct ( AbstractAdapter $adapterConfig )
30
    {
31
        parent::__construct ( $adapterConfig );
32
        if ( $adapterConfig->hasSchemas () ) {
33
            $this->schema = $adapterConfig->getSchemas ();
34
        }
35
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    protected function convertTypeToSimple ( $str )
42
    {
43
        if ( preg_match ( '/(tinyint|bit)/' , $str ) )
44
        {
45
            $res = 'boolean';
46
        } elseif ( preg_match ( '/(date|time|text|binary|char|xml|uniqueidentifier)/' , $str ) )
47
        {
48
            $res = 'string';
49
        } elseif ( preg_match ( '/(decimal|numeric|real|float|money)/' , $str ) )
50
        {
51
            $res = 'float';
52
        } elseif ( preg_match ( '#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#' , $str , $matches ) )
53
        {
54
            $res = $matches[ 1 ];
55
        }
56
57
        return $res;
0 ignored issues
show
Bug introduced by
The variable $res does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
58
    }
59
60
    protected function getHost(){
61
        $host = $this->host;
62
        if (!empty($this->port)) {
63
            $seperator = ':';
64
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
65
                $seperator = ',';
66
            }
67
            $host .=  $seperator . $this->port;
68
            unset($this->port);
69
        }
70
71
        return $host;
72
    }
73
74
    /**
75
     * @inheritDoc
76
     * @return string
77
     */
78
    public function getPDOString ()
79
    {
80
        return sprintf (
81
            "mssql:host=%s;dbname=%s" ,
82
            $this->getHost() ,
83
            $this->database
84
        );
85
    }
86
87
    /**
88
     * @inheritDoc
89
     * @return string
90
     */
91
    public function getPDOSocketString ()
92
    {
93
        // TODO: implement here
94
        return "";
95
    }
96
97
    /**
98
     * @inheritDoc
99
     * @return string[]
100
     */
101 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...
102
    {
103
        if ( empty( $this->tableList ) )
104
        {
105
106
            $sqlTables = ! empty( $this->tablesName )
107
                ? "AND table_name IN ( $this->tablesName )" : '';
108
109
            $strSchema = implode ( "', '" , $this->schema );
110
111
            $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...
112
                                    ->query (
113
                                        "SELECT table_schema,
114
              table_name
115
             FROM {$this->database}.information_schema.tables
116
             WHERE
117
              table_type = 'BASE TABLE'
118
              AND table_schema IN ( '$strSchema' ) $sqlTables
119
              ORDER by
120
               table_schema,
121
               table_name
122
              ASC"
123
                                    )
124
                                    ->fetchAll ();
125
        }
126
127
        return $this->tableList;
128
    }
129
130
    /**
131
     * retorna multiplos arrays com dados da column em array
132
     *
133
     * @return array[]
134
     */
135
136
    /**
137
     * retorna multiplos arrays com dados da column em array
138
     *
139
     * @return array
140
     */
141
    public function getListColumns ()
142
    {
143
        $sqlTables = ! empty( $this->tablesName )
144
            ? "AND c.table_name IN ( $this->tablesName )" : '';
145
        $strSchema = implode ( "', '" , $this->schema );
146
147
        return $this->getPDO ()
148
                    ->query (
149
                        "SELECT distinct
150
	c.table_schema,
151
	c.table_name,
152
	c.column_name ,
153
	c.data_type,
154
	c.column_default,
155
	is_nullable,
156
	character_maximum_length AS max_length
157
		FROM
158
		{$this->database}.information_schema.tables AS st
159
		INNER JOIN  {$this->database}.information_schema.columns AS c
160
		ON st.table_name=c.table_name and st.table_type = 'BASE TABLE'
161
		 $sqlTables and  c.table_schema IN ('$strSchema')
162
		order by c.table_name asc"
163
                    )
164
                    ->fetchAll ( \PDO::FETCH_ASSOC );
165
    }
166
167
    /**
168
     * retorna o numero total de tabelas
169
     *
170
     * @return int
171
     */
172 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...
173
    {
174
        if ( empty( $this->totalTables ) )
175
        {
176
            $sqlTables = ! empty( $this->tablesName )
177
                ? "AND table_name IN ( $this->tablesName )" : '';
178
179
            $strSchema = implode ( "', '" , $this->schema );
180
181
            $this->totalTables = $this->getPDO ()
182
                                      ->query (
183
                                          "SELECT COUNT(table_name)  AS total
184
             FROM {$this->database}.information_schema.tables
185
             WHERE
186
              table_type = 'BASE TABLE'
187
              AND table_schema IN ( '" . $strSchema . "' ) $sqlTables"
188
                                      )
189
                                      ->fetchColumn ();
190
        }
191
192
        return (int) $this->totalTables;
193
    }
194
195
    public function getSequence ( $table , $column , $schema = 0 )
196
    {
197
        $return = $this->getPDO ()
198
                       ->query (
199
                           "SELECT is_identity FROM sys.columns WHERE object_id = object_id('{$schema}.{$table}')  AND name = '{$column}';"
200
                       )
201
                       ->fetchColumn();
202
203
        if ( ! $return )
204
        {
205
            return;
206
        }
207
208
        return "{$table}_{$column}_seq";
209
    }
210
211
    /**
212
     * @return array
213
     */
214
    public function getListConstrant ()
215
    {
216
        return array();
217
    }
218
219
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
220
    public function getListConstrant ()
221
    {
222
        $sqlTables = ! empty( $this->tablesName )
223
            ? "AND tc.table_name IN ( $this->tablesName )" : '';
224
        $strSchema = implode ( "', '" , $this->schema );
225
226
        return $this->getPDO ()
227
                    ->query (
228
                        "
229
SELECT DISTINCT
230
                tc.constraint_type,
231
                tc.constraint_name,
232
                tc.table_schema,
233
                tc.table_name,
234
                kcu.column_name,
235
		        ccu.table_schema AS foreign_schema,
236
                ccu.table_name AS foreign_table,
237
                ccu.column_name as foreign_column
238
            FROM
239
                {$this->database}.INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
240
            INNER JOIN {$this->database}.INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu
241
                      ON tc.constraint_name = kcu.constraint_name
242
                       AND tc.table_schema IN ('$strSchema')
243
                       AND tc.constraint_type IN ('FOREIGN KEY','PRIMARY KEY')
244
                       $sqlTables
245
            INNER JOIN {$this->database}.information_schema.constraint_column_usage AS ccu
246
                      ON tc.constraint_name  = ccu.constraint_name
247
                      ORDER by tc.table_schema;"
248
                    )
249
                    ->fetchAll ( \PDO::FETCH_ASSOC );
250
    }
251
    */
252
253
}
254