Passed
Push — master ( 17efdf...07a51e )
by Andrea
60:38
created

Fifree2installCommand::generateDefaultData()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 396
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 280
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 396
ccs 280
cts 280
cp 1
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 34
nc 1
nop 2
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Fi\CoreBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
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
12
class Fifree2installCommand extends ContainerAwareCommand
13
{
14
15 4
    protected $fixtureFile;
16
17 4
    protected function configure()
18 4
    {
19 4
        $this
20 4
                ->setName('fifree2:install')
21 4
                ->setDescription('Installazione ambiente fifree')
22 4
                ->setHelp('Crea il database, un utente amministratore e i dati di default')
23 4
                ->addArgument('admin', InputArgument::REQUIRED, 'Username per amministratore')
24
                ->addArgument('adminpass', InputArgument::REQUIRED, 'Password per amministratore')
25 4
                ->addArgument('adminemail', InputArgument::REQUIRED, 'Email per amministratore')
26
        ;
27 1
    }
28
29 1
    protected function execute(InputInterface $input, OutputInterface $output)
30 1
    {
31 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...
32
        $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...
33 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...
34
        $this->fixtureFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'fixtures.yml';
35
36
        if (!$admin) {
37
            echo "Inserire il nome utente dell'amministratore";
38 1
39
            return 1;
40
        }
41
        if (!$adminpass) {
42
            echo "Inserire la password per dell'amministratore";
43 1
44
            return 1;
45
        }
46
        if (!$adminemail) {
47
            echo "Inserire la mail dell'amministratore";
48
49 1
            return 1;
50 1
        }
51 1
52 1
        $commanddb = $this->getApplication()->find('fifree2: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...
53
        $argumentsdb = array('command' => 'fifree2:createdatabase');
54 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...
55
        $commanddb->run($inputc, $output);
56 1
57 1
        $this->generateDefaultData($admin, $adminemail);
58 1
59 1
        $commanddata = $this->getApplication()->find('fifree2: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...
60 1
        $argumentsdata = array(
61 1
            'command' => 'fifree2:configuratorimport',
62
            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...
63 1
        );
64 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...
65
        $commanddata->run($inputd, $output);
66 1
67
        $fs = new Filesystem();
68 1
        $fs->remove($this->fixtureFile);
69
70 1
        $userManipulator = $this->getContainer()->get('fifree.fos_user.util.user_manipulator');
71 1
72 1
        $userManipulator->changePassword($admin, $adminpass);
73 1
    }
74 1
75 1
    /**
76 1
     * This will suppress UnusedLocalVariable
77 1
     * warnings in this method
78 1
     *
79 1
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
80 1
     */
81 1
    private function generateDefaultData($admin, $adminemail)
82 1
    {
83 1
        $defaultData = <<<EOF
84 1
Fi\CoreBundle\Entity\Ruoli:
85 1
  -
86 1
    id: 1
87 1
    ruolo: 'Super Admin'
88 1
    paginainiziale: /adminpanel
89 1
    is_superadmin: true
90 1
    is_admin: true
91 1
    is_user: false
92
  -
93
    id: 2
94 1
    ruolo: Amministratore
95 1
    paginainiziale: /adminpanel
96 1
    is_superadmin: false
97 1
    is_admin: true
98 1
    is_user: false
99
  -
100 1
    id: 3
101
    ruolo: Utente
102 1
    paginainiziale: /ffprincipale
103
    is_superadmin: false
104 1
    is_admin: false
105 1
    is_user: true
106 1
Fi\CoreBundle\Entity\Operatori:
107 1
  -
108 1
    username: $admin
109
    usernameCanonical: $admin
110 1
    email: $adminemail
111 1
    emailCanonical: $adminemail
112 1
    enabled: true
113 1
    salt: null
114 1
    password: $admin
115
    lastLogin: null
116 1
    confirmationToken: null
117 1
    passwordRequestedAt: null
118 1
    roles:
119 1
      - ROLE_SUPER_ADMIN
120 1
    id: 1
121
    operatore: $admin
122 1
    ruoli_id: 1
123 1
Fi\CoreBundle\Entity\Permessi:
124 1
  -
125 1
    id: 1
126 1
    modulo: MenuApplicazione
127
    crud: crud
128 1
    operatori_id: null
129 1
    ruoli_id: 1
130 1
  -
131 1
    id: 2
132 1
    modulo: OpzioniTabella
133
    crud: crud
134 1
    operatori_id: null
135 1
    ruoli_id: 1
136 1
  -
137 1
    id: 3
138 1
    modulo: Tabelle
139
    crud: crud
140 1
    operatori_id: null
141 1
    ruoli_id: 1
142 1
  -
143 1
    id: 4
144 1
    modulo: Permessi
145
    crud: crud
146 1
    operatori_id: null
147 1
    ruoli_id: 1
148 1
  -
149 1
    id: 5
150 1
    modulo: Operatori
151
    crud: cru
152 1
    operatori_id: null
153 1
    ruoli_id: 1
154 1
  -
155
    id: 6
156 1
    modulo: Ruoli
157 1
    crud: crud
158 1
    operatori_id: null
159 1
    ruoli_id: 1
160 1
  -
161 1
    id: 7
162 1
    modulo: Ffprincipale
163
    crud: crud
164 1
    operatori_id: null
165 1
    ruoli_id: 1
166 1
  -
167 1
    id: 8
168 1
    modulo: Ffsecondaria
169 1
    crud: crud
170 1
    operatori_id: null
171
    ruoli_id: 1
172
Fi\CoreBundle\Entity\Tabelle:
173 1
  -
174 1
    id: 1
175 1
    nometabella: '*'
176 1
    nomecampo: null
177 1
    mostraindex: null
178
    ordineindex: null
179 1
    larghezzaindex: null
180 1
    etichettaindex: null
181 1
    mostrastampa: null
182 1
    ordinestampa: null
183 1
    larghezzastampa: null
184 1
    etichettastampa: null
185
    operatori_id: null
186 1
    registrastorico: null
187 1
  -
188
    id: 2
189 1
    nometabella: Ffsecondaria
190
    nomecampo: ffprincipale
191 1
    mostraindex: true
192 1
    ordineindex: null
193 1
    larghezzaindex: null
194 1
    etichettaindex: null
195 1
    mostrastampa: true
196 1
    ordinestampa: null
197
    larghezzastampa: null
198 1
    etichettastampa: null
199 1
    operatori_id: null
200 1
    registrastorico: true
201 1
  -
202 1
    id: 3
203 1
    nometabella: Ffsecondaria
204 1
    nomecampo: descsec
205
    mostraindex: true
206 1
    ordineindex: null
207 1
    larghezzaindex: null
208 1
    etichettaindex: null
209 1
    mostrastampa: true
210 1
    ordinestampa: null
211 1
    larghezzastampa: null
212 1
    etichettastampa: null
213 1
    operatori_id: null
214
    registrastorico: true
215 1
Fi\CoreBundle\Entity\OpzioniTabella:
216 1
  -
217 1
    id: 1
218 1
    tabelle_id: 1
219 1
    descrizione: null
220 1
    parametro: titolo
221
    valore: 'Elenco dati per %tabella%'
222 1
  -
223 1
    id: 2
224 1
    tabelle_id: 1
225 1
    descrizione: 'Altezza Griglia'
226 1
    parametro: altezzagriglia
227 1
    valore: '400'
228 1
Fi\CoreBundle\Entity\Ffprincipale:
229
  -
230 1
    id: 1
231 1
    descrizione: 'Descrizione primo record'
232 1
  -
233 1
    id: 2
234 1
    descrizione: 'Descrizione secondo record'
235 1
Fi\CoreBundle\Entity\Ffsecondaria:
236 1
  -
237
    id: 1
238 1
    descsec: '1° secondaria legato al 1° record principale'
239 1
    ffprincipale_id: 1
240 1
    data: 2018-02-15T00:00:00+01:00
241 1
    intero: 10
242 1
    importo: 12.34
243 1
    nota: 'Super Nota ffsecondaria'
244 1
    attivo: true
245
  -
246 1
    id: 2
247 1
    descsec: '2° secondaria legato al 1° record principale'
248 1
    ffprincipale_id: 1
249 1
    data: 2018-02-15T00:00:00+01:00
250 1
    intero: 1
251 1
    importo: 1.23
252 1
    nota: 'Nota ffsecondaria'
253 1
    attivo: true
254
  -
255 1
    id: 3
256 1
    descsec: '3° secondaria legato al 1° record principale'
257 1
    ffprincipale_id: 1
258 1
    data: 2018-02-15T00:00:00+01:00
259 1
    intero: 10
260 1
    importo: 11.34
261 1
    nota: 'Nota 3° ffsecondaria'
262
    attivo: false
263 1
  -
264 1
    id: 4
265 1
    descsec: '4° secondaria legato al 1° record principale'
266 1
    ffprincipale_id: 1
267 1
    data: 2018-02-15T00:00:00+01:00
268 1
    intero: 101
269 1
    importo: 101.34
270
    nota: 'Nota 4° ffsecondaria'
271 1
    attivo: true
272 1
  -
273 1
    id: 5
274 1
    descsec: '5° secondaria legato al 1° record principale'
275 1
    ffprincipale_id: 1
276 1
    data: 2018-02-15T00:00:00+01:00
277 1
    intero: 101
278
    importo: 101.34
279 1
    nota: 'Nota 4° ffsecondaria'
280 1
    attivo: true
281 1
  -
282 1
    id: 6
283 1
    descsec: '6° secondaria legato al 2° record principale'
284 1
    ffprincipale_id: 2
285 1
    data: 2018-02-15T00:00:00+01:00
286
    intero: 10006
287 1
    importo: 10006.12
288 1
    nota: 'Nota altra ffsecondaria'
289 1
    attivo: true
290 1
  -
291 1
    id: 7
292 1
    descsec: '7° secondaria legato al 2° record principale'
293 1
    ffprincipale_id: 2
294 1
    data: 2018-02-15T00:00:00+01:00
295 1
    intero: 10007
296
    importo: 10007.22
297 1
    nota: 'Nota altra 7 ffsecondaria'
298
    attivo: false
299 1
  -
300 1
    id: 8
301 1
    descsec: '9° secondaria legato al 2° "record principale"'
302 1
    ffprincipale_id: 2
303 1
    data: 2018-02-15T00:00:00+01:00
304 1
    intero: 1000
305 1
    importo: 1000.12
306 1
    nota: 'Nota altra ffsecondaria'
307 1
    attivo: true
308 1
  -
309 1
    id: 9
310 1
    descsec: '10° secondaria legato al 2° record principale ed è l''ultimo record'
311 1
    ffprincipale_id: 2
312
    data: 2018-02-15T00:00:00+01:00
313 1
    intero: 1100
314 1
    importo: 1100.99
315 1
    nota: 'Nota 10° altra ffsecondaria'
316 1
    attivo: false
317 1
Fi\CoreBundle\Entity\MenuApplicazione:
318 1
  -
319 1
    id: 1
320 1
    nome: Tabelle
321
    percorso: null
322 1
    padre: null
323
    ordine: 10
324 1
    attivo: true
325 1
    target: null
326 1
    tag: null
327 1
    notifiche: null
328 1
    autorizzazionerichiesta: null
329 1
    percorsonotifiche: null
330 1
  -
331 1
    id: 2
332
    nome: FFprincipale
333 1
    percorso: Ffprincipale
334
    padre: 1
335 1
    ordine: 10
336 1
    attivo: true
337 1
    target: null
338 1
    tag: null
339 1
    notifiche: null
340 1
    autorizzazionerichiesta: null
341 1
    percorsonotifiche: null
342 1
  -
343
    id: 3
344 1
    nome: FFsecondaria
345
    percorso: Ffsecondaria
346 1
    padre: 1
347 1
    ordine: 10
348 1
    attivo: true
349 1
    target: null
350 1
    tag: null
351 1
    notifiche: null
352 1
    autorizzazionerichiesta: null
353 1
    percorsonotifiche: null
354
  -
355 1
    id: 4
356
    nome: Amministrazione
357 1
    percorso: null
358 1
    padre: null
359 1
    ordine: 20
360
    attivo: true
361 1
    target: null
362 1
    tag: null
363 1
    notifiche: null
364 1
    autorizzazionerichiesta: null
365 1
    percorsonotifiche: null
366 1
  -
367 1
    id: 5
368 1
    nome: Operatori
369
    percorso: Operatori
370 1
    padre: 4
371
    ordine: 10
372 1
    attivo: true
373 1
    target: null
374 1
    tag: null
375 1
    notifiche: null
376 1
    autorizzazionerichiesta: null
377 1
    percorsonotifiche: null
378 1
  -
379 1
    id: 6
380
    nome: Ruoli
381 1
    percorso: Ruoli
382 1
    padre: 4
383 1
    ordine: 20
384 1
    attivo: true
385 1
    target: null
386 1
    tag: null
387 1
    notifiche: null
388 1
    autorizzazionerichiesta: null
389
    percorsonotifiche: null
390 1
  -
391 1
    id: 7
392 1
    nome: Permessi
393 1
    percorso: Permessi
394 1
    padre: 4
395 1
    ordine: 30
396 1
    attivo: true
397 1
    target: null
398 1
    tag: null
399 1
    notifiche: null
400
    autorizzazionerichiesta: null
401 1
    percorsonotifiche: null
402 1
  -
403 1
    id: 8
404 1
    nome: 'Gestione tabelle'
405 1
    percorso: null
406 1
    padre: 4
407 1
    ordine: 40
408 1
    attivo: true
409 1
    target: null
410 1
    tag: null
411
    notifiche: null
412
    autorizzazionerichiesta: null
413
    percorsonotifiche: null
414
  -
415
    id: 9
416
    nome: Tabelle
417
    percorso: Tabelle
418
    padre: 8
419
    ordine: 10
420
    attivo: true
421
    target: null
422
    tag: null
423
    notifiche: null
424
    autorizzazionerichiesta: null
425
    percorsonotifiche: null
426
  -
427
    id: 10
428
    nome: 'Opzioni tabella'
429
    percorso: OpzioniTabella
430
    padre: 8
431
    ordine: 20
432
    attivo: true
433
    target: null
434
    tag: null
435
    notifiche: null
436
    autorizzazionerichiesta: null
437
    percorsonotifiche: null
438
  -
439
    id: 11
440
    nome: 'Menu Applicazione'
441
    percorso: MenuApplicazione_container
442
    padre: 4
443
    ordine: 50
444
    attivo: true
445
    target: null
446
    tag: null
447
    notifiche: null
448
    autorizzazionerichiesta: null
449
    percorsonotifiche: null
450
  -
451
    id: 12
452
    nome: Utilità
453
    percorso: fi_pannello_amministrazione_homepage
454
    padre: 4
455
    ordine: 100
456
    attivo: true
457
    target: null
458
    tag: null
459
    notifiche: null
460
    autorizzazionerichiesta: null
461
    percorsonotifiche: null
462
  -
463
    id: 13
464
    nome: FiDemo
465
    percorso: fi_demo_index
466
    padre: 4
467
    ordine: 150
468
    attivo: false
469
    target: null
470
    tag: null
471
    notifiche: null
472
    autorizzazionerichiesta: null
473
    percorsonotifiche: null
474
EOF;
475
        $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...
476
        $fs->dumpFile($this->fixtureFile, $defaultData);
477
    }
478
}
479