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 ( 2b8f20...fd3b95 )
by Pedro
02:38
created

build/Classes/AdapterConfig/AbstractAdapter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Classes\AdapterConfig;
4
5
require_once 'Exception.php';
6
7
/**
8
 * @author Pedro Alarcao <[email protected]>
9
 * @link   https://github.com/pedro151
10
 */
11
abstract class AbstractAdapter
12
{
13
14
    protected $arrConfig = array (
15
        ############################# DATABASE
16
        //Driver do banco de dados
17
        'driver'   => null ,
18
        //Nome do banco de dados
19
        'database' => null ,
20
        //Host do banco
21
        'host'     => 'localhost' ,
22
        //Port do banco
23
        'port'     => '' ,
24
        //usuario do banco
25
        'username' => null ,
26
        //senha do banco
27
        'password' => null ,
28
        // lista de schemas do banco de dados
29
        'schema'   => array () ,
30
31
        'socket'          => null ,
32
33
        ########################### DOCS
34
        // autor que gerou o script
35
        'author'          => "Pedro" ,
36
        'license'         => "New BSD License" ,
37
        'copyright'       => "DAO Generator-Pedro151" ,
38
        'link'            => 'https://github.com/pedro151' ,
39
        // data que foi gerado o script
40
        'last_modify'     => null ,
41
42
        ########################## Ambiente/Arquivos
43
44
        // Nome do framework para o adapter
45
        'framework'       => null ,
46
        // namespace das classes
47
        'namespace'       => "" ,
48
        // caminho onde os arquivos devem ser criados
49
        'path'            => 'models' ,
50
        // flag para gerar pasta com o nome do driver do banco de dados
51
        'folder-database' => 0 ,
52
53
        ############################## Comandos adicionais
54
        //flag para mostrar o status da execução ao termino do processo
55
        'status'          => false ,
56
        // flags para criar todas as tabelas ou nao
57
        'allTables'       => true ,
58
        //Lista de tabelas a serem ignoradas
59
        'ignoreTable'     => array () ,
60
    );
61
62
    /**
63
     * @var string[] um array com todos os campos obrigatorios
64
     */
65
    protected $attRequered = array (
66
        'driver'   => true ,
67
        'database' => true ,
68
        'host'     => true ,
69
        'username' => true ,
70
       // 'password' => true ,
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
71
        'path'     => true
72
    );
73
74
    protected $arrFunc = array ();
75
76
    private $framworkFiles = array ();
77
78
    /**
79
     * verifica se todos valores obrigatorios tem valor
80
     *
81
     * @return bool
82
     */
83
    protected function checkConfig ()
84
    {
85
        if ( array_diff_key ( $this->attRequered , array_filter ( $this->arrConfig ) ) )
86
        {
87
            return false;
88
        }
89
90
        return true;
91
    }
92
93
    /**
94
     * retorna os parametros da configuração do framework
95
     *
96
     * @return array
97
     */
98
    abstract protected function getParams ();
99
100
    /**
101
     * Popula as config do generater com as configuraçoes do framework
102
     *
103
     * @return mixed
104
     */
105
    abstract protected function parseFrameworkConfig ();
106
107
    /**
108
     * @param \Classes\Db\DbTable|\Classes\Db\Constrant $table
109
     *
110
     * @return mixed
111
     */
112
    abstract public function createClassNamespace ( $table );
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
    public function __construct ( $array )
124
    {
125
        $array += array (
126
            'author'      => ucfirst ( get_current_user () ) ,
127
            'last_modify' => date ( "d-m-Y H:i:s." )
128
        );
129
130
        $this->setFrameworkFiles ( $array );
131
        $this->parseFrameworkConfig ();
132
        $this->setParams ( $this->getParams () );
133
        $this->setParams ( $array );
134
        $this->init ();
135
        if ( ! $this->isValid () )
136
        {
137
            $var = array_diff_key ( $this->attRequered , array_filter ( $this->arrConfig ) );
138
            throw new Exception( $var );
139
        }
140
    }
141
142
    /**
143
     * Set os arquivos de configuracao do framework
144
     *
145
     * @param $array
146
     */
147
    public function setFrameworkFiles ( $array )
148
    {
149
        $this->framworkFiles[ 'library' ] = isset( $array[ 'framework-path-library' ] )
150
            ? $array[ 'framework-path-library' ]
151
            : null;
152
153
        $this->framworkFiles[ 'ini' ] = isset( $array[ 'framework-ini' ] )
154
            ? $array[ 'framework-ini' ]
155
            : null;
156
157
        $this->framworkFiles[ 'environment' ] = isset( $array[ 'environment' ] )
158
            ? $array[ 'environment' ]
159
            : 'production';
160
161
    }
162
163
    protected function isValidFrameworkFiles ()
164
    {
165
        if ( ! is_file ( $this->framworkFiles[ 'ini' ] ) )
166
        {
167
            return false;
168
        }
169
170
        if ( ! is_dir ( $this->framworkFiles[ 'library' ] ) )
171
        {
172
            return false;
173
        }
174
175
176
        if ( ! isset ( $this->framworkFiles[ 'environment' ] )
177
             or empty( $this->framworkFiles[ 'environment' ] )
178
        )
179
        {
180
            return false;
181
        }
182
        set_include_path (
183
            implode (
184
                PATH_SEPARATOR ,
185
                array (
186
                    realpath ( $this->framworkFiles[ 'library' ] ) ,
187
                    get_include_path () ,
188
                )
189
            )
190
        );
191
192
        return true;
193
    }
194
195
    protected function getFrameworkIni ()
196
    {
197
        return $this->framworkFiles[ 'ini' ];
198
    }
199
200
    protected function getEnvironment ()
201
    {
202
        return $this->framworkFiles[ 'environment' ];
203
    }
204
205
    /**
206
     * Popula as variaveis de acordo com o arquivo de configuração do seu  framework
207
     */
208
    protected function isValid ()
209
    {
210
        return $this->checkConfig ();
211
    }
212
213
    private function setParams ( $array )
214
    {
215
        if ( count ( $array ) > 0 )
216
        {
217
            $this->arrConfig = array_filter ( $array ) + $this->arrConfig;
218
        }
219
    }
220
221
    /**
222
     * @return string
223
     */
224
    public function getDatabase ()
225
    {
226
        return $this->arrConfig[ 'database' ];
227
    }
228
229
    /**
230
     * @return bool
231
     */
232
    public function hasSchemas ()
233
    {
234
        return ! empty ( $this->arrConfig[ 'schema' ] );
235
    }
236
237
    /**
238
     * @return string[]
239
     */
240
    public function getSchemas ()
241
    {
242
        if ( is_string ( $this->arrConfig[ 'schema' ] ) )
243
        {
244
            return array ( $this->arrConfig[ 'schema' ] );
245
        }
246
247
        return $this->arrConfig[ 'schema' ];
248
    }
249
250
    public function setSchema ( $schema )
251
    {
252
        $this->arrConfig[ 'schema' ] = $schema;
253
    }
254
255
    /**
256
     * @return string
257
     */
258
    public function getHost ()
259
    {
260
        return $this->arrConfig[ 'host' ];
261
    }
262
263
    /**
264
     * @return int
265
     */
266
    public function getPort ()
267
    {
268
        return $this->arrConfig[ 'port' ];
269
    }
270
271
    /**
272
     * @return boolean
273
     */
274
    public function hasPort ()
275
    {
276
        return ! empty( $this->arrConfig[ 'port' ] );
277
    }
278
279
    /**
280
     * @return string
281
     */
282
    public function getSocket ()
283
    {
284
        return $this->arrConfig[ 'socket' ];
285
    }
286
287
    /**
288
     * @return string
289
     */
290
    public function getUser ()
291
    {
292
        return $this->arrConfig[ 'username' ];
293
    }
294
295
    /**
296
     * @return string
297
     */
298
    public function getPassword ()
299
    {
300
        return $this->arrConfig[ 'password' ];
301
    }
302
303
    /**
304
     * @return bool
305
     */
306
    public function isStatusEnabled ()
307
    {
308
        return (bool) $this->arrConfig[ 'status' ];
309
    }
310
311
    /**
312
     * @param $str
313
     *
314
     * @return string
315
     */
316
    public function __get ( $str )
317
    {
318
        $arr = array (
319
            'namespace' ,
320
            'framework' ,
321
            'author' ,
322
            'license' ,
323
            'copyright' ,
324
            'link' ,
325
            'last_modify' ,
326
            'path' ,
327
            'folder-database'
328
        );
329
330
        if ( in_array ( $str , $arr ) )
331
        {
332
            return $this->arrConfig[ strtolower ( $str ) ];
333
        }
334
335
        return;
336
    }
337
338
}
339