Completed
Push — master ( e12569...5b5661 )
by Gilmar
23:28
created

ScreenplayCommand::all()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 2
eloc 18
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of gpupo/netshoes-sdk
5
 * Created by Gilmar Pupo <[email protected]>
6
 * For the information of copyright and license you should read the file
7
 * LICENSE which is distributed with this source code.
8
 * Para a informação dos direitos autorais e de licença você deve ler o arquivo
9
 * LICENSE que é distribuído com este código-fonte.
10
 * Para obtener la información de los derechos de autor y la licencia debe leer
11
 * el archivo LICENSE que se distribuye con el código fuente.
12
 * For more information, see <http://www.g1mr.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Console\Command;
16
17
use Symfony\Component\Console\Input\ArrayInput;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * @codeCoverageIgnore
24
 */
25
class ScreenplayCommand extends AbstractCommand
26
{
27
    protected $list = ['all', 'main'];
28
29
    protected function screenplayList()
30
    {
31
        return  include 'screenplay.config.php';
32
    }
33
34
    public function all($app)
35
    {
36
        $screenplayList = $this->screenplayList();
37
38
        $this->getApp()->appendCommand('screenplay:run', 'Run all scripts')
39
       ->addArgument('path', InputArgument::REQUIRED, 'Script Directory')
40
       ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $screenplayList) {
41
           $list = $app->processInputParameters([], $input, $output);
0 ignored issues
show
Unused Code introduced by
$list is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
           $path = $input->getArgument('path');
43
           $output->writeln('Utilizando arquivos do diretório ['.$path.']');
44
45
           foreach ($screenplayList as $key => $value) {
46
               $s = 'screenplay:'.$key;
47
               $command = $app->find($s);
48
               $t = new ArrayInput([
49
                   'command' => $s,
50
                   'path'    => $path,
51
               ]);
52
53
               $output->writeln("\n");
54
               $output->writeln('./bin/netshoes-sdk ' . $s);
55
56
               $command->run($t, $output);
57
58
               $output->writeln("\n------");
59
60
           }
61
       });
62
    }
63
64
    public function main($app)
65
    {
66
        foreach ($this->screenplayList() as $key => $todo) {
67
            $cname = 'screenplay:'.$key;
68
            $filename = str_replace(':', '.', $cname).'.php';
69
            $this->getApp()->appendCommand($cname, $todo)
70
                ->addArgument('path', InputArgument::REQUIRED, 'Script Directory')
71
                ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $filename, $todo) {
72
                    $list = $app->processInputParameters([], $input, $output);
73
                    $path = $input->getArgument('path');
74
75
                    $filePath = $path.$filename;
76
                    $output->writeln('<options=bold>'.$todo.'</> | ' . $filePath);
77
78
                    if (!file_exists($filePath)) {
79
                        copy(__DIR__.'/screenplay.template.php', $filePath);
80
                    }
81
82
                    $sdk = $app->factorySdk($list);
83
                    $implemented = false;
84
85
                    include $filePath;
86
87
                    if (empty($implemented)) {
88
                        $output->writeln('- <error>'.$filePath.' FAIL!</>');
89
                        throw new \Exception("Abort!");
90
                    }
91
                });
92
        }
93
    }
94
}
95