Passed
Push — master ( 632657...4bf89d )
by Andrea
24:52
created

BiCoreBundleInstallCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\BiCoreBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Input\ArrayInput;
11
use FOS\UserBundle\Util\UserManipulator;
12
13
class BiCoreBundleInstallCommand extends Command
14
{
15
16
    protected $fixtureFile;
17
    private $usermanipulator;
18
19 1
    protected function configure()
20
    {
21
        $this
22 1
                ->setName('bicorebundle:install')
23 1
                ->setDescription('Installazione ambiente bi')
24 1
                ->setHelp('Crea il database, un utente amministratore e i dati di default')
25 1
                ->addArgument('admin', InputArgument::REQUIRED, 'Username per amministratore')
26 1
                ->addArgument('adminpass', InputArgument::REQUIRED, 'Password per amministratore')
27 1
                ->addArgument('adminemail', InputArgument::REQUIRED, 'Email per amministratore')
28
        ;
29 1
    }
30
31 1
    public function __construct(UserManipulator $usermanipulator)
32
    {
33 1
        $this->usermanipulator = $usermanipulator;
34
35
        // you *must* call the parent constructor
36 1
        parent::__construct();
37 1
    }
38
39 1
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41 1
        $admin = $input->getArgument('admin');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42 1
        $adminpass = $input->getArgument('adminpass');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
43 1
        $adminemail = $input->getArgument('adminemail');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44 1
        $this->fixtureFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'fixtures.yml';
45
46 1
        if (!$admin) {
47
            echo "Inserire il nome utente dell'amministratore";
48
49
            return 1;
50
        }
51 1
        if (!$adminpass) {
52
            echo "Inserire la password per dell'amministratore";
53
54
            return 1;
55
        }
56 1
        if (!$adminemail) {
57
            echo "Inserire la mail dell'amministratore";
58
59
            return 1;
60
        }
61
62 1
        $commanddb = $this->getApplication()->find('bicorebundle:createdatabase');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63 1
        $argumentsdb = array('command' => 'bicorebundle:createdatabase');
64 1
        $inputc = new ArrayInput($argumentsdb);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
65 1
        $commanddb->run($inputc, $output);
66
67 1
        $this->generateDefaultData($admin, $adminemail);
68
69 1
        $commanddata = $this->getApplication()->find('bicorebundle:configuratorimport');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
70
        $argumentsdata = array(
71 1
            'command' => 'bicorebundle:configuratorimport',
72
            array("--truncatetables" => true)
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal --truncatetables does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
73
        );
74 1
        $inputd = new ArrayInput($argumentsdata);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
75 1
        $commanddata->run($inputd, $output);
76
77 1
        $fs = new Filesystem();
78 1
        $fs->remove($this->fixtureFile);
79
80 1
        $userManipulator = $this->usermanipulator;
81
82 1
        $userManipulator->changePassword($admin, $adminpass);
0 ignored issues
show
Bug introduced by
It seems like $admin can also be of type string[]; however, parameter $username of FOS\UserBundle\Util\User...lator::changePassword() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $userManipulator->changePassword(/** @scrutinizer ignore-type */ $admin, $adminpass);
Loading history...
Bug introduced by
It seems like $adminpass can also be of type string[]; however, parameter $password of FOS\UserBundle\Util\User...lator::changePassword() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $userManipulator->changePassword($admin, /** @scrutinizer ignore-type */ $adminpass);
Loading history...
83 1
    }
84
85
    /**
86
     * This will suppress UnusedLocalVariable
87
     * warnings in this method
88
     *
89
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
90
     */
91 1
    private function generateDefaultData($admin, $adminemail)
92
    {
93
        //$todaydt = new \DateTime();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
94
        //$today = $todaydt->format("Y-m-d") . "T00:00:00+01:00";
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
95
        
96
        $defaultData = <<<EOF
97
Cdf\BiCoreBundle\Entity\Ruoli:
98
    -
99
        id: 1
100
        ruolo: 'Super Admin'
101
        paginainiziale: /adminpanel
102
        superadmin: true
103
        admin: true
104
        user: false
105
    -
106
        id: 2
107
        ruolo: Amministratore
108
        paginainiziale: /adminpanel
109
        superadmin: false
110
        admin: true
111
        user: false
112
    -
113
        id: 3
114
        ruolo: Utente
115
        paginainiziale: /
116
        superadmin: false
117
        admin: false
118
        user: true
119
Cdf\BiCoreBundle\Entity\Operatori:
120
    -
121 1
        username: $admin
122 1
        usernameCanonical: $admin
123 1
        email: $adminemail
124 1
        emailCanonical: $adminemail
125
        enabled: true
126
        salt: null
127 1
        password: $admin
128
        lastLogin: null
129
        confirmationToken: null
130
        passwordRequestedAt: null
131
        roles:
132
            - ROLE_SUPER_ADMIN
133
        id: 1
134 1
        operatore: $admin
135
        ruoli_id: 1
136
    -
137
        username: userreadroles
138
        usernameCanonical: userreadroles
139
        email: [email protected]
140
        emailCanonical: [email protected]
141
        enabled: true
142
        salt: mNVzoSgms1k9JU2Eb/syehddayryUqNDh0LFzjggcCM
143
        password: 1yNtksQ2XpN+zj/Jk9IP0MpBZcaBxg0nltY+EML4Vlv3cJ8g6U6/YaejAP+tagemH2N2htTqP7tELs2ZhlRAHw==
144
        lastLogin: null
145
        confirmationToken: null
146
        passwordRequestedAt: null
147
        roles: {  }
148
        id: 2
149
        operatore: null
150
        ruoli_id: 3
151
    -
152
        username: usernoroles
153
        usernameCanonical: usernoroles
154
        email: [email protected]
155
        emailCanonical: [email protected]
156
        enabled: true
157
        salt: nczIukArDyAEH6vvjehM973qvfDjE.WGzkP24umtpfE
158
        password: Ce0FJ16dd5HfwJ8CbzocZB3UDZWzwvD9l/A3kyJJR1oHoisxGjF06qR4sSj/Nsk8J6aCI1GtgmHbJfeF7TS93w==
159
        lastLogin: null
160
        confirmationToken: null
161
        passwordRequestedAt: null
162
        roles: {  }
163
        id: 3
164
        operatore: null
165
        ruoli_id: 3                
166
Cdf\BiCoreBundle\Entity\Permessi:
167
    -
168
        id: 1
169
        modulo: Menuapplicazione
170
        crud: crud
171
        operatori_id: null
172
        ruoli_id: 1
173
    -
174
        id: 2
175
        modulo: Opzionitabella
176
        crud: crud
177
        operatori_id: null
178
        ruoli_id: 1
179
    -
180
        id: 3
181
        modulo: Tabelle
182
        crud: crud
183
        operatori_id: null
184
        ruoli_id: 1
185
    -
186
        id: 4
187
        modulo: Permessi
188
        crud: crud
189
        operatori_id: null
190
        ruoli_id: 1
191
    -
192
        id: 5
193
        modulo: Operatori
194
        crud: cru
195
        operatori_id: null
196
        ruoli_id: 1
197
    -
198
        id: 6
199
        modulo: Ruoli
200
        crud: crud
201
        operatori_id: null
202
        ruoli_id: 2
203
    -
204
        id: 7
205
        modulo: Cliente
206
        crud: crud
207
        operatori_id: null
208
        ruoli_id: 2
209
    -
210
        id: 8
211
        modulo: Fornitore
212
        crud: crud
213
        operatori_id: null
214
        ruoli_id: 2
215
    -
216
        id: 9
217
        modulo: Prodottofornitore
218
        crud: crud
219
        operatori_id: null
220
        ruoli_id: 2
221
    -
222
        id: 10
223
        modulo: Ordine
224
        crud: crud
225
        operatori_id: null
226
        ruoli_id: 2
227
    -
228
        id: 11
229
        modulo: Ordine
230
        crud: crud
231
        operatori_id: null
232
        ruoli_id: 2
233
    -
234
        id: 12
235
        modulo: Magazzino
236
        crud: r
237
        operatori_id: 2
238
        ruoli_id: null
239
240
Cdf\BiCoreBundle\Entity\Colonnetabelle:
241
  -
242
    id: 1
243
    nometabella: '*'
244
    nomecampo: null
245
    mostraindex: null
246
    ordineindex: null
247
    larghezzaindex: null
248
    etichettaindex: null
249
    operatori_id: null
250
    registrastorico: null
251
    editabile: null
252
  -
253
    id: 2
254
    nometabella: Permessi
255
    nomecampo: modulo
256
    mostraindex: true
257
    ordineindex: 20
258
    larghezzaindex: 20
259
    etichettaindex: Modulo
260
    operatori_id: null
261
    registrastorico: true
262
    editabile: true
263
  -
264
    id: 3
265
    nometabella: Permessi
266
    nomecampo: crud
267
    mostraindex: true
268
    ordineindex: 30
269
    larghezzaindex: 20
270
    etichettaindex: CRUD
271
    operatori_id: null
272
    registrastorico: true
273
    editabile: true
274
  -
275
    id: 4
276
    nometabella: Permessi
277
    nomecampo: ruoli
278
    mostraindex: true
279
    ordineindex: 50
280
    larghezzaindex: 20
281
    etichettaindex: Ruolo
282
    operatori_id: null
283
    registrastorico: true
284
    editabile: true
285
  -
286
    id: 5
287
    nometabella: Permessi
288
    nomecampo: operatori
289
    mostraindex: true
290
    ordineindex: 60
291
    larghezzaindex: 20
292
    etichettaindex: Operatore
293
    operatori_id: null
294
    registrastorico: true
295
    editabile: true
296
297
Cdf\BiCoreBundle\Entity\Opzionitabelle:
298
  -
299
    id: 1
300
    nometabella: '*'
301
    descrizione: null
302
    parametro: titolo
303
    valore: 'Elenco dati per %tabella%'
304
  -
305
    id: 2
306
    nometabella: '*'
307
    descrizione: 'Altezza Griglia'
308
    parametro: altezzagriglia
309
    valore: '400'
310
311
Cdf\BiCoreBundle\Entity\Menuapplicazione:
312
  -
313
    id: 1
314
    nome: Amministrazione
315
    percorso: null
316
    padre: null
317
    ordine: 20
318
    attivo: true
319
    target: null
320
    tag: Amministrazione
321
    notifiche: null
322
    autorizzazionerichiesta: true
323
    percorsonotifiche: null
324
  -
325
    id: 2
326
    nome: Operatori
327
    percorso: Operatori
328
    padre: 1
329
    ordine: 10
330
    attivo: true
331
    target: null
332
    tag: null
333
    notifiche: null
334
    autorizzazionerichiesta: null
335
    percorsonotifiche: null
336
  -
337
    id: 3
338
    nome: Ruoli
339
    percorso: Ruoli
340
    padre: 1
341
    ordine: 20
342
    attivo: true
343
    target: null
344
    tag: null
345
    notifiche: null
346
    autorizzazionerichiesta: null
347
    percorsonotifiche: null
348
  -
349
    id: 4
350
    nome: Permessi
351
    percorso: Permessi
352
    padre: 1
353
    ordine: 30
354
    attivo: true
355
    target: null
356
    tag: null
357
    notifiche: null
358
    autorizzazionerichiesta: null
359
    percorsonotifiche: null
360
  -
361
    id: 5
362
    nome: 'Gestione tabelle di sistema'
363
    percorso: null
364
    padre: 1
365
    ordine: 40
366
    attivo: true
367
    target: null
368
    tag: null
369
    notifiche: null
370
    autorizzazionerichiesta: null
371
    percorsonotifiche: null
372
  -
373
    id: 6
374
    nome: 'Colonne tabelle'
375
    percorso: Colonnetabelle
376
    padre: 5
377
    ordine: 10
378
    attivo: true
379
    target: null
380
    tag: null
381
    notifiche: null
382
    autorizzazionerichiesta: null
383
    percorsonotifiche: null
384
  -
385
    id: 7
386
    nome: 'Opzioni tabelle'
387
    percorso: Opzionitabelle
388
    padre: 5
389
    ordine: 20
390
    attivo: true
391
    target: null
392
    tag: null
393
    notifiche: null
394
    autorizzazionerichiesta: null
395
    percorsonotifiche: null
396
  -
397
    id: 8
398
    nome: 'Menu Applicazione'
399
    percorso: Menuapplicazione
400
    padre: 1
401
    ordine: 50
402
    attivo: true
403
    target: null
404
    tag: null
405
    notifiche: null
406
    autorizzazionerichiesta: null
407
    percorsonotifiche: null
408
  -
409
    id: 9
410
    nome: Utilità
411
    percorso: fi_pannello_amministrazione_homepage
412
    padre: 1
413
    ordine: 100
414
    attivo: true
415
    target: null
416
    tag: null
417
    notifiche: null
418
    autorizzazionerichiesta: null
419
    percorsonotifiche: null
420
EOF;
421 1
        $fs = new Filesystem();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
422 1
        $fs->dumpFile($this->fixtureFile, $defaultData);
423 1
    }
424
}
425