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 ( 5502fa...062bdf )
by Pedro
02:42
created

Config::factoryDriver()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 14
rs 7.7777
cc 8
eloc 9
nc 8
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 25 and the first side effect is on line 13.

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;
4
5
use Classes\AdapterConfig\None;
6
use Classes\AdapterConfig\ZendFrameworkOne;
7
use Classes\AdaptersDriver\Dblib;
8
use Classes\AdaptersDriver\Mssql;
9
use Classes\AdaptersDriver\Mysql;
10
use Classes\AdaptersDriver\Pgsql;
11
use Classes\AdaptersDriver\Sqlsrv;
12
13
require_once 'AdapterConfig/None.php';
14
require_once 'AdapterConfig/ZendFrameworkOne.php';
15
require_once 'AdaptersDriver/Dblib.php';
16
require_once 'AdaptersDriver/Mssql.php';
17
require_once 'AdaptersDriver/Mysql.php';
18
require_once 'AdaptersDriver/Pgsql.php';
19
require_once 'AdaptersDriver/Sqlsrv.php';
20
21
/**
22
 * @author Pedro Alarcao <[email protected]>
23
 * @link   https://github.com/pedro151/ORM-Generator
24
 */
25
class Config
26
{
27
28
    /**
29
     * @var string
30
     */
31
    public static $version = "1.2.0";
32
33
    /**
34
     * String that separates the parent section name
35
     *
36
     * @var string
37
     */
38
    protected $sectionSeparator = ':';
39
40
    /**
41
     * @var string
42
     */
43
    private $configIniDefault = '/configs/config.ini';
44
45
    /**
46
     * @var string
47
     */
48
    public $_basePath;
49
    /**
50
     * @var array
51
     */
52
    private $argv = array ();
53
54
    /**
55
     * @var \Classes\AdapterConfig\AbstractAdapter
56
     */
57
    private $adapterConfig;
58
59
    /**
60
     * @var \Classes\AdaptersDriver\AbsractAdapter
61
     */
62
    private $adapterDriver;
63
64
    public function __construct ( $argv , $basePath )
65
    {
66
        if ( array_key_exists ( 'help' , $argv ) )
67
        {
68
            die ( $this->getUsage () );
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
69
        }
70
        if ( array_key_exists ( 'status' , $argv ) )
71
        {
72
            $argv[ 'status' ] = true;
73
        }
74
75
        $this->argv = $this->parseConfig ( $basePath , $argv );
76
    }
77
78
    /**
79
     * Lista de ajuda quando digita 'help'
80
     *
81
     * @return string
82
     */
83
    public function getUsage ()
84
    {
85
        $version = static::$version;
86
87
        return <<<EOF
88
parameters:
89
90
    --init                : Creates the necessary configuration file to start using the ORM-Generator.
91
    --config-ini          : reference to another .ini file configuration (relative path).
92
    --config-env          : ORM-Generator configuration environment.
93
    --framework           : name framework used, which has the contents of the database configurations and framework template.
94
    --driver              : database driver name (Ex.: pgsql).
95
    --database            : database name.
96
 *  --schema              : database schema name (one or more than one).
97
    --status              : show status of implementation carried out after completing the process.
98
    --version             : shows the version of ORM-Generator.
99
    --help                : help command explaining all the options and manner of use.
100
    --path                  specify where to create the files (default is current directory).
101
102
 example: php generate.php --framework=zend_framework --database=foo --table=foobar --status
103
104
ORM-Generator By: Pedro Alarcao Version: $version
105
EOF;
106
    }
107
108
    public function getVersion ()
109
    {
110
        $version = static::$version;
111
112
        return "ORM-Generator By: Pedro Alarcao Version: $version";
113
    }
114
115
    /**
116
     * Analisa e estrutura a Configuracao do generate
117
     *
118
     * @param  string $basePath
119
     * @param array   $argv
120
     *
121
     * @return array
122
     * @throws \Exception
123
     */
124
    private function parseConfig ( $basePath , $argv )
125
    {
126
        $this->_basePath = dirname ( $basePath );
127
128
        $configIni = isset( $argv[ 'config-ini' ] ) ? $argv[ 'config-ini' ]
129
            : $this->_basePath . $this->configIniDefault;
130
131
        $configTemp = $this->loadIniFile ( realpath ( $configIni ) );
132
        $configCurrent = self::parseConfigEnv ( $configTemp , $argv );
133
134
        if ( ! isset( $configCurrent[ 'framework' ] ) )
135
        {
136
            throw new \Exception( "configure which framework you want to use! \n" );
137
        }
138
139
        return $argv + array_filter ( $configCurrent );
140
    }
141
142
    /**
143
     *
144
     * @param $configTemp
145
     * @param $argv
146
     *
147
     * @return string
148
     */
149
    private static function parseConfigEnv ( $configTemp , $argv )
150
    {
151
        $thisSection = isset( $configTemp[ key ( $configTemp ) ][ 'config-env' ] ) ?
152
            $configTemp[ key ( $configTemp ) ][ 'config-env' ] : null;
153
154
        $thisSection = isset( $argv[ 'config-env' ] ) ? $argv[ 'config-env' ]
155
            : $thisSection;
156
157
        if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) )
158
        {
159
            #faz marge da config principal com a config extendida
160
            return $configTemp[ $thisSection ]
161
                   + $configTemp[ $configTemp[ $thisSection ][ 'extends' ] ];
162
        }
163
164
        return $configTemp[ key ( $configTemp ) ];
165
    }
166
167
    /**
168
     * Carregar o arquivo ini e pré-processa o separador de seção ':'
169
     * no nome da seção (que é usado para a extensão seção) de modo a que a
170
     * matriz resultante tem os nomes de seção corretos e as informações de
171
     * extensão é armazenado em uma sub-ch ve
172
     *
173
     * @param string $filename
174
     *
175
     * @throws \Exception
176
     * @return array
177
     */
178
    protected function loadIniFile ( $filename )
179
    {
180
        if ( ! is_file ( $filename ) )
181
        {
182
            throw new \Exception( "configuration file does not exist! \n" );
183
        }
184
185
        $loaded = parse_ini_file ( $filename , true );
186
        $iniArray = array ();
187
        foreach ( $loaded as $key => $data )
188
        {
189
            $pieces = explode ( $this->sectionSeparator , $key );
190
            $thisSection = trim ( $pieces[ 0 ] );
191
            switch ( count ( $pieces ) )
192
            {
193
                case 1:
194
                    $iniArray[ $thisSection ] = $data;
195
                    break;
196
197
                case 2:
198
                    $extendedSection = trim ( $pieces[ 1 ] );
199
                    $iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ) , $data );
200
                    break;
201
202
                default:
203
                    throw new \Exception( "Section '$thisSection' may not extend multiple sections in $filename" );
204
            }
205
        }
206
207
        return $iniArray;
208
    }
209
210
    /**
211
     * analisa a opção e cria a instancia do Atapter do determinado framework
212
     *
213
     */
214
    private function factoryConfig ()
215
    {
216
        switch ( strtolower ( $this->argv[ 'framework' ] ) )
217
        {
218
            case 'none':
219
                $this->adapterConfig = new None( $this->argv );
220
                break;
221
            case 'zend_framework':
222
                $this->adapterConfig = new ZendFrameworkOne( $this->argv );
223
                break;
224
        }
225
226
    }
227
228
    /**
229
     * Analisa a opção e instancia o determinado banco de dados
230
     *
231
     */
232
    private function factoryDriver ()
233
    {
234
        switch ( $this->argv[ 'driver' ] )
235
        {
236
            case 'pgsql':
237
            case 'pdo_pgsql': $this->adapterDriver = new Pgsql( $this->getAdapterConfig () ); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
238
            case 'mysql':
239
            case 'pdo_mysql': $this->adapterDriver = new Mysql( $this->getAdapterConfig () ); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
240
            case 'mssql': $this->adapterDriver = new Mssql( $this->getAdapterConfig () ); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
241
            case 'dblib':$this->adapterDriver = new Dblib( $this->getAdapterConfig () ); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
242
            case 'sqlsrv': $this->adapterDriver = new Sqlsrv( $this->getAdapterConfig () ); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
243
        }
244
245
    }
246
247
    /**
248
     * @return AdapterConfig\AbstractAdapter
249
     */
250
    public function getAdapterConfig ()
251
    {
252
        if ( ! $this->adapterConfig )
253
        {
254
            $this->factoryConfig ();
255
        }
256
257
        return $this->adapterConfig;
258
    }
259
260
    /**
261
     * @return AdaptersDriver\AbsractAdapter
262
     */
263
    public function getAdapterDriver ()
264
    {
265
        if ( ! $this->adapterDriver )
266
        {
267
            $this->factoryDriver ();
268
        }
269
270
        return $this->adapterDriver;
271
    }
272
273
}
274