Completed
Push — master ( 30080a...e12569 )
by Gilmar
25:12
created

ScreenplayCommand::productPostMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 1
eloc 6
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 Closure;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\Console\Input\ArrayInput;
22
23
/**
24
 * @codeCoverageIgnore
25
 */
26
class ScreenplayCommand extends AbstractCommand
27
{
28
    protected $list = ['all', 'main'];
29
30
    protected function screenplayList()
31
    {
32
        return  include 'screenplay.config.php';
33
    }
34
35
   public function all($app)
36
   {
37
       $screenplayList = $this->screenplayList();
38
39
       $this->getApp()->appendCommand('screenplay:run', 'Run all scripts')
40
       ->addArgument('path', InputArgument::REQUIRED, 'Script Directory')
41
       ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $screenplayList) {
42
           $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...
43
           $path =  $input->getArgument('path');
44
           $output->writeln('Utilizando arquivos do diretório [' . $path . ']');
45
46
           foreach($screenplayList as $key => $value) {
47
               $s = 'screenplay:'.$key;
48
               $command = $app->find($s);
49
               $t = new ArrayInput([
50
                   'command' => $s,
51
                   'path'   => $path,
52
               ]);
53
               $command->run($t, $output);
54
           }
55
       });
56
   }
57
58
    public function main($app)
59
    {
60
        foreach($this->screenplayList() as $key => $todo) {
61
            $cname = 'screenplay:' . $key;
62
            $filename = str_replace(':', '.', $cname) . '.php';
63
            $this->getApp()->appendCommand($cname, $todo)
64
                ->addArgument('path', InputArgument::REQUIRED, 'Script Directory')
65
                ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $filename, $todo) {
66
                    $list = $app->processInputParameters([], $input, $output);
67
                    $path =  $input->getArgument('path');
68
69
                    $filePath = $path . $filename;
70
                    $output->writeln('- <info>'.$todo.'</info>');
71
                    $output->writeln('Executando ' . $filePath);
72
73
                    if (!file_exists($filePath)) {
74
                        copy(__DIR__ . '/screenplay.template.php', $filePath);
75
                    }
76
77
                    $sdk = $app->factorySdk($list);
78
                    $implemented = false;
79
80
                    include $filePath;
81
82
                    if(empty($implemented)) {
83
                        $output->writeln('- <error>'.$filePath.' FAIL!</>');
84
85
                        throw new \Exception("Abort");
86
87
                    }
88
                });
89
        }
90
    }
91
}
92