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 ( f4782c...853a03 )
by Pedro
06:07 queued 03:22
created

AbstractAdapter   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 370
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 14
Bugs 5 Features 0
Metric Value
wmc 41
c 14
b 5
f 0
lcom 2
cbo 2
dl 0
loc 370
rs 8.2769

27 Methods

Rating   Name   Duplication   Size   Complexity  
A isStatusEnabled() 0 4 1
A checkConfig() 0 8 2
getParams() 0 1 ?
parseFrameworkConfig() 0 1 ?
getMakeFileInstances() 0 1 ?
init() 0 1 ?
A getBaseNamespace() 0 7 1
B createClassNamespace() 0 25 6
A __construct() 0 17 2
A setFrameworkFiles() 0 9 4
B isValidFrameworkFiles() 0 26 5
A getFrameworkIni() 0 4 1
A getEnvironment() 0 4 1
A isValid() 0 4 1
A setParams() 0 6 2
A getDatabase() 0 4 1
A hasSchemas() 0 4 1
A getSchemas() 0 8 2
A setSchema() 0 4 1
A getHost() 0 4 1
A getPort() 0 4 1
A hasPort() 0 4 1
A getSocket() 0 4 1
A getUser() 0 4 1
A getPassword() 0 4 1
A replaceReservedWord() 0 8 2
A __get() 0 21 2

How to fix   Complexity   

Complex Class

Complex classes like AbstractAdapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AbstractAdapter, and based on these observations, apply Extract Interface, too.

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
        // string com o nome da pastar personalizada
56
        'folder-name'     => '',
57
58
        ############################## Comandos adicionais
59
        //flag para mostrar o status da execução ao termino do processo
60
        'status'          => false,
61
        // flags para criar todas as tabelas ou nao
62
        'allTables'       => true,
63
        //Lista de tabelas a serem ignoradas
64
        'ignoreTable'     => array (),
65
    );
66
67
    /**
68
     * @var string[] um array com todos os campos obrigatorios
69
     */
70
    protected $attRequered = array (
71
        'driver'   => true,
72
        'database' => true,
73
        'host'     => true,
74
        'username' => true,
75
        'path'     => true
76
    );
77
78
    protected $arrFunc = array ();
79
80
    private $framworkFiles = array ();
81
82
    public $reservedWord = array ();
83
84
    const SEPARETOR = "";
85
86
    /**
87
     * verifica se todos valores obrigatorios tem valor
88
     *
89
     * @return bool
90
     */
91
    protected function checkConfig ()
92
    {
93
        if ( array_diff_key ( $this->attRequered, array_filter ( $this->arrConfig ) ) ) {
94
            return false;
95
        }
96
97
        return true;
98
    }
99
100
    /**
101
     * retorna os parametros da configuração do framework
102
     *
103
     * @return array
104
     */
105
    abstract protected function getParams ();
106
107
    /**
108
     * Popula as config do generater com as configuraçoes do framework
109
     *
110
     * @return mixed
111
     */
112
    abstract protected function parseFrameworkConfig ();
113
114
    /**
115
     * Cria Instancias dos arquivos que devem ser gerados
116
     *
117
     * @return \Classes\AdapterMakerFile\AbstractAdapter[]
118
     */
119
    abstract public function getMakeFileInstances ();
120
121
    abstract protected function init ();
122
123
    /**
124
     * retorna a base do Namespace
125
     *
126
     * @return array
127
     */
128
    protected function getBaseNamespace ()
129
    {
130
        return array (
131
            $this->arrConfig[ 'namespace' ],
132
            'Model'
133
        );
134
    }
135
136
    /**
137
     * @param \Classes\Db\DbTable|\Classes\Db\Constrant $table
138
     *
139
     * @return mixed
140
     */
141
142
    public function createClassNamespace ( $table )
143
    {
144
        $arrNames = $this->getBaseNamespace ();
145
146
        if ( isset( $this->arrConfig[ 'folder-database' ] )
147
             && $this->arrConfig[ 'folder-database' ]
148
        ) {
149
            $arrNames[] = AbstractMaker::getClassName ( $this->arrConfig[ 'driver' ] );
150
        }
151
152
        if ( isset( $this->arrConfig[ 'folder-name' ] )
153
             && $this->arrConfig[ 'folder-name' ]
154
        ) {
155
            $arrNames[] = AbstractMaker::getClassName ( $this->arrConfig[ 'folder-name' ] );
156
        }
157
158
        if ( $table->hasSchema () ) {
159
            $arrNames[] = $this->replaceReservedWord ( AbstractMaker::getClassName ( $table->getSchema () ) );
160
        }
161
        else {
162
            $arrNames[] = $this->replaceReservedWord ( AbstractMaker::getClassName ( $table->getDatabase () ) );
163
        }
164
165
        return implode ( static::SEPARETOR, array_filter ( $arrNames ) );
166
    }
167
168
    public function __construct ( $array )
169
    {
170
        $array += array (
171
            'author'      => ucfirst ( get_current_user () ),
172
            'last_modify' => date ( "d-m-Y H:i:s." )
173
        );
174
175
        $this->setFrameworkFiles ( $array );
176
        $this->parseFrameworkConfig ();
177
        $this->setParams ( $this->getParams () );
178
        $this->setParams ( $array );
179
        $this->init ();
180
        if ( !$this->isValid () ) {
181
            $var = array_diff_key ( $this->attRequered, array_filter ( $this->arrConfig ) );
182
            throw new Exception( $var );
183
        }
184
    }
185
186
    /**
187
     * Set os arquivos de configuracao do framework
188
     *
189
     * @param $array
190
     */
191
    public function setFrameworkFiles ( $array )
192
    {
193
        $this->framworkFiles[ 'library' ] = isset( $array[ 'framework-path-library' ] ) ? $array[ 'framework-path-library' ] : null;
194
195
        $this->framworkFiles[ 'ini' ] = isset( $array[ 'framework-ini' ] ) ? $array[ 'framework-ini' ] : null;
196
197
        $this->framworkFiles[ 'environment' ] = isset( $array[ 'environment' ] ) ? $array[ 'environment' ] : 'production';
198
199
    }
200
201
    protected function isValidFrameworkFiles ()
202
    {
203
        if ( !is_file ( $this->framworkFiles[ 'ini' ] ) ) {
204
            return false;
205
        }
206
207
        if ( !is_dir ( $this->framworkFiles[ 'library' ] ) ) {
208
            return false;
209
        }
210
211
212
        if ( !isset ( $this->framworkFiles[ 'environment' ] ) 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...
213
            return false;
214
        }
215
        set_include_path (
216
            implode (
217
                PATH_SEPARATOR,
218
                array (
219
                    realpath ( $this->framworkFiles[ 'library' ] ),
220
                    get_include_path (),
221
                )
222
            )
223
        );
224
225
        return true;
226
    }
227
228
    protected function getFrameworkIni ()
229
    {
230
        return $this->framworkFiles[ 'ini' ];
231
    }
232
233
    protected function getEnvironment ()
234
    {
235
        return $this->framworkFiles[ 'environment' ];
236
    }
237
238
    /**
239
     * Popula as variaveis de acordo com o arquivo de configuração do seu  framework
240
     */
241
    protected function isValid ()
242
    {
243
        return $this->checkConfig ();
244
    }
245
246
    private function setParams ( $array )
247
    {
248
        if ( count ( $array ) > 0 ) {
249
            $this->arrConfig = array_filter ( $array ) + $this->arrConfig;
250
        }
251
    }
252
253
    /**
254
     * @return string
255
     */
256
    public function getDatabase ()
257
    {
258
        return $this->arrConfig[ 'database' ];
259
    }
260
261
    /**
262
     * @return bool
263
     */
264
    public function hasSchemas ()
265
    {
266
        return !empty ( $this->arrConfig[ 'schema' ] );
267
    }
268
269
    /**
270
     * @return string[]
271
     */
272
    public function getSchemas ()
273
    {
274
        if ( is_string ( $this->arrConfig[ 'schema' ] ) ) {
275
            return array ( $this->arrConfig[ 'schema' ] );
276
        }
277
278
        return $this->arrConfig[ 'schema' ];
279
    }
280
281
    public function setSchema ( $schema )
282
    {
283
        $this->arrConfig[ 'schema' ] = $schema;
284
    }
285
286
    /**
287
     * @return string
288
     */
289
    public function getHost ()
290
    {
291
        return $this->arrConfig[ 'host' ];
292
    }
293
294
    /**
295
     * @return int
296
     */
297
    public function getPort ()
298
    {
299
        return $this->arrConfig[ 'port' ];
300
    }
301
302
    /**
303
     * @return boolean
304
     */
305
    public function hasPort ()
306
    {
307
        return !empty( $this->arrConfig[ 'port' ] );
308
    }
309
310
    /**
311
     * @return string
312
     */
313
    public function getSocket ()
314
    {
315
        return $this->arrConfig[ 'socket' ];
316
    }
317
318
    /**
319
     * @return string
320
     */
321
    public function getUser ()
322
    {
323
        return $this->arrConfig[ 'username' ];
324
    }
325
326
    /**
327
     * @return string
328
     */
329
    public function getPassword ()
330
    {
331
        return $this->arrConfig[ 'password' ];
332
    }
333
334
    /**
335
     * @param string $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...
336
     *
337
     * @return string
338
     */
339
    public function replaceReservedWord ( $palavra )
340
    {
341
        if ( isset( $this->reservedWord[ strtolower ( $palavra ) ] ) ) {
342
            return $this->reservedWord[ strtolower ( $palavra ) ];
343
        }
344
345
        return $palavra;
346
    }
347
348
    /**
349
     * @return bool
350
     */
351
    public function isStatusEnabled ()
352
    {
353
        return (bool) $this->arrConfig[ 'status' ];
354
    }
355
356
    /**
357
     * @param $str
358
     *
359
     * @return string
360
     */
361
    public function __get ( $str )
362
    {
363
        $arr = array (
364
            'namespace',
365
            'framework',
366
            'author',
367
            'license',
368
            'copyright',
369
            'link',
370
            'last_modify',
371
            'path',
372
            'folder-database',
373
            'folder-name'
374
        );
375
376
        if ( in_array ( $str, $arr ) ) {
377
            return $this->arrConfig[ strtolower ( $str ) ];
378
        }
379
380
        return;
381
    }
382
383
}
384