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 ( 660260...e1c224 )
by Pedro
03:36
created

AbstractAdapter::setFrameworkFiles()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 10
nc 8
nop 1
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 14 and the first side effect is on line 7.

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\AdapterConfig;
4
5
use Classes\Maker\AbstractMaker;
6
7
require_once "Classes/Maker/AbstractMaker.php";
8
require_once 'Exception.php';
9
10
/**
11
 * @author Pedro Alarcao <[email protected]>
12
 * @link   https://github.com/pedro151/orm-generator
13
 */
14
abstract class AbstractAdapter
15
{
16
17
    protected $arrConfig = array (
18
        ############################# DATABASE
19
        //Driver do banco de dados
20
        'driver'   => null ,
21
        //Nome do banco de dados
22
        'database' => null ,
23
        //Host do banco
24
        'host'     => 'localhost' ,
25
        //Port do banco
26
        'port'     => '' ,
27
        //usuario do banco
28
        'username' => null ,
29
        //senha do banco
30
        'password' => null ,
31
        // lista de schemas do banco de dados
32
        'schema'   => array () ,
33
34
        'socket'          => null ,
35
36
        ########################### DOCS
37
        // autor que gerou o script
38
        'author'          => "Pedro" ,
39
        'license'         => "New BSD License" ,
40
        'copyright'       => "ORM Generator - Pedro151" ,
41
        'link'            => 'https://github.com/pedro151/orm-generator' ,
42
        // data que foi gerado o script
43
        'last_modify'     => null ,
44
45
        ########################## Ambiente/Arquivos
46
47
        // Nome do framework para o adapter
48
        'framework'       => null ,
49
        // namespace das classes
50
        'namespace'       => "" ,
51
        // caminho onde os arquivos devem ser criados
52
        'path'            => 'models' ,
53
        // flag para gerar pasta com o nome do driver do banco de dados
54
        'folder-database' => 0 ,
55
56
        ############################## Comandos adicionais
57
        //flag para mostrar o status da execução ao termino do processo
58
        'status'          => false ,
59
        // flags para criar todas as tabelas ou nao
60
        'allTables'       => true ,
61
        //Lista de tabelas a serem ignoradas
62
        'ignoreTable'     => array () ,
63
    );
64
65
    /**
66
     * @var string[] um array com todos os campos obrigatorios
67
     */
68
    protected $attRequered = array (
69
        'driver'   => true ,
70
        'database' => true ,
71
        'host'     => true ,
72
        'username' => true ,
73
        'path'     => true
74
    );
75
76
    protected $arrFunc = array ();
77
78
    private $framworkFiles = array ();
79
80
    const SEPARETOR = "";
81
82
    /**
83
     * verifica se todos valores obrigatorios tem valor
84
     *
85
     * @return bool
86
     */
87
    protected function checkConfig ()
88
    {
89
        if ( array_diff_key ( $this->attRequered , array_filter ( $this->arrConfig ) ) )
90
        {
91
            return false;
92
        }
93
94
        return true;
95
    }
96
97
    /**
98
     * retorna os parametros da configuração do framework
99
     *
100
     * @return array
101
     */
102
    abstract protected function getParams ();
103
104
    /**
105
     * Popula as config do generater com as configuraçoes do framework
106
     *
107
     * @return mixed
108
     */
109
    abstract protected function parseFrameworkConfig ();
110
111
    /**
112
     * Cria Instancias dos arquivos que devem ser gerados
113
     *
114
     * @return \Classes\AdapterMakerFile\AbstractAdapter[]
115
     */
116
    abstract public function getMakeFileInstances ();
117
118
    abstract protected function init ();
119
120
    /**
121
     * retorna a base do Namespace
122
     *
123
     * @return array
124
     */
125
    protected function getBaseNamespace ()
126
    {
127
        return array (
128
            $this->arrConfig[ 'namespace' ] ,
129
            'Model'
130
        );
131
    }
132
133
    /**
134
     * @param \Classes\Db\DbTable|\Classes\Db\Constrant $table
135
     *
136
     * @return mixed
137
     */
138
139
    public function createClassNamespace ( $table )
140
    {
141
        $arrNames = $this->getBaseNamespace ();
142
143
        if ( isset( $this->arrConfig[ 'folder-database' ] )
144
             && $this->arrConfig[ 'folder-database' ]
145
        )
146
        {
147
            $arrNames[] = AbstractMaker::getClassName ( $this->arrConfig[ 'driver' ] );
148
        }
149
150
        if ( $table->hasSchema () )
151
        {
152
            $arrNames[] = AbstractMaker::getClassName ( $table->getSchema () );
153
        } else
154
        {
155
            $arrNames[] = AbstractMaker::getClassName ( $table->getDatabase () );
156
        }
157
158
        return implode ( static::SEPARETOR , array_filter ( $arrNames ) );
159
    }
160
161
    public function __construct ( $array )
162
    {
163
        $array += array (
164
            'author'      => ucfirst ( get_current_user () ) ,
165
            'last_modify' => date ( "d-m-Y H:i:s." )
166
        );
167
168
        $this->setFrameworkFiles ( $array );
169
        $this->parseFrameworkConfig ();
170
        $this->setParams ( $this->getParams () );
171
        $this->setParams ( $array );
172
        $this->init ();
173
        if ( ! $this->isValid () )
174
        {
175
            $var = array_diff_key ( $this->attRequered , array_filter ( $this->arrConfig ) );
176
            throw new Exception( $var );
177
        }
178
    }
179
180
    /**
181
     * Set os arquivos de configuracao do framework
182
     *
183
     * @param $array
184
     */
185
    public function setFrameworkFiles ( $array )
186
    {
187
        $this->framworkFiles[ 'library' ] = isset( $array[ 'framework-path-library' ] )
188
            ? $array[ 'framework-path-library' ]
189
            : null;
190
191
        $this->framworkFiles[ 'ini' ] = isset( $array[ 'framework-ini' ] )
192
            ? $array[ 'framework-ini' ]
193
            : null;
194
195
        $this->framworkFiles[ 'environment' ] = isset( $array[ 'environment' ] )
196
            ? $array[ 'environment' ]
197
            : 'production';
198
199
    }
200
201
    protected function isValidFrameworkFiles ()
202
    {
203
        if ( ! is_file ( $this->framworkFiles[ 'ini' ] ) )
204
        {
205
            return false;
206
        }
207
208
        if ( ! is_dir ( $this->framworkFiles[ 'library' ] ) )
209
        {
210
            return false;
211
        }
212
213
214
        if ( ! isset ( $this->framworkFiles[ 'environment' ] )
215
             or empty( $this->framworkFiles[ 'environment' ] )
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
216
        )
217
        {
218
            return false;
219
        }
220
        set_include_path (
221
            implode (
222
                PATH_SEPARATOR ,
223
                array (
224
                    realpath ( $this->framworkFiles[ 'library' ] ) ,
225
                    get_include_path () ,
226
                )
227
            )
228
        );
229
230
        return true;
231
    }
232
233
    protected function getFrameworkIni ()
234
    {
235
        return $this->framworkFiles[ 'ini' ];
236
    }
237
238
    protected function getEnvironment ()
239
    {
240
        return $this->framworkFiles[ 'environment' ];
241
    }
242
243
    /**
244
     * Popula as variaveis de acordo com o arquivo de configuração do seu  framework
245
     */
246
    protected function isValid ()
247
    {
248
        return $this->checkConfig ();
249
    }
250
251
    private function setParams ( $array )
252
    {
253
        if ( count ( $array ) > 0 )
254
        {
255
            $this->arrConfig = array_filter ( $array ) + $this->arrConfig;
256
        }
257
    }
258
259
    /**
260
     * @return string
261
     */
262
    public function getDatabase ()
263
    {
264
        return $this->arrConfig[ 'database' ];
265
    }
266
267
    /**
268
     * @return bool
269
     */
270
    public function hasSchemas ()
271
    {
272
        return ! empty ( $this->arrConfig[ 'schema' ] );
273
    }
274
275
    /**
276
     * @return string[]
277
     */
278
    public function getSchemas ()
279
    {
280
        if ( is_string ( $this->arrConfig[ 'schema' ] ) )
281
        {
282
            return array ( $this->arrConfig[ 'schema' ] );
283
        }
284
285
        return $this->arrConfig[ 'schema' ];
286
    }
287
288
    public function setSchema ( $schema )
289
    {
290
        $this->arrConfig[ 'schema' ] = $schema;
291
    }
292
293
    /**
294
     * @return string
295
     */
296
    public function getHost ()
297
    {
298
        return $this->arrConfig[ 'host' ];
299
    }
300
301
    /**
302
     * @return int
303
     */
304
    public function getPort ()
305
    {
306
        return $this->arrConfig[ 'port' ];
307
    }
308
309
    /**
310
     * @return boolean
311
     */
312
    public function hasPort ()
313
    {
314
        return ! empty( $this->arrConfig[ 'port' ] );
315
    }
316
317
    /**
318
     * @return string
319
     */
320
    public function getSocket ()
321
    {
322
        return $this->arrConfig[ 'socket' ];
323
    }
324
325
    /**
326
     * @return string
327
     */
328
    public function getUser ()
329
    {
330
        return $this->arrConfig[ 'username' ];
331
    }
332
333
    /**
334
     * @return string
335
     */
336
    public function getPassword ()
337
    {
338
        return $this->arrConfig[ 'password' ];
339
    }
340
341
    /**
342
     * @return bool
343
     */
344
    public function isStatusEnabled ()
345
    {
346
        return (bool) $this->arrConfig[ 'status' ];
347
    }
348
349
    /**
350
     * @param $str
351
     *
352
     * @return string
353
     */
354
    public function __get ( $str )
355
    {
356
        $arr = array (
357
            'namespace' ,
358
            'framework' ,
359
            'author' ,
360
            'license' ,
361
            'copyright' ,
362
            'link' ,
363
            'last_modify' ,
364
            'path' ,
365
            'folder-database'
366
        );
367
368
        if ( in_array ( $str , $arr ) )
369
        {
370
            return $this->arrConfig[ strtolower ( $str ) ];
371
        }
372
373
        return;
374
    }
375
376
}
377