ScreenplayCommand::main()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 9.408
c 0
b 0
f 0
cc 3
nc 2
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 <https://www.gpupo.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
final 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
            $path = $input->getArgument('path');
42
            $output->writeln('Utilizando arquivos do diretório ['.$path.']');
43
44
            foreach ($screenplayList as $key => $value) {
45
                $s = 'screenplay:'.$key;
46
                $command = $app->find($s);
47
                $t = new ArrayInput([
48
                   'command' => $s,
49
                   'path'    => $path,
50
                ]);
51
52
                $command->run($t, $output);
53
            }
54
        });
55
    }
56
57
    public function main($app)
58
    {
59
        foreach ($this->screenplayList() as $key => $todo) {
60
            $cname = 'screenplay:'.$key;
61
            $pow = explode(':', $key);
62
            $f = current($pow);
63
            $filename = str_replace([$f.':', ':'], [$f.'/', '.'], $key).'.php';
64
            $this->getApp()->appendCommand($cname, $todo)
65
                ->addArgument('path', InputArgument::REQUIRED, 'Script Directory')
66
                ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $filename, $todo, $cname) {
67
                    $list = $app->processInputParameters([], $input, $output);
68
                    $path = $input->getArgument('path');
69
70
                    $filePath = $path.$filename;
71
                    $output->writeln("\n".'<options=bold>'.$todo.'</>');
72
73
                    if (!file_exists($filePath)) {
74
                        throw new \Exception('Roteiro não implementado:'.$filePath, 1);
75
                    }
76
77
                    $sdk = $app->factorySdk($list, 'screenplay', true);
78
79
                    $sdk->getLogger()->addDebug($cname, [
80
                        'file' => $filePath,
81
                    ]);
82
83
                    $implemented = false;
84
85
                    require $filePath;
86
                });
87
        }
88
    }
89
}
90