Issues (36)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Console/Command/OrderCommand.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Closure;
18
use Gpupo\CommonSchema\TranslatorDataCollection;
19
use Symfony\Component\Console\Input\InputArgument;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * @codeCoverageIgnore
25
 */
26
final class OrderCommand extends AbstractCommand
27
{
28
    protected $list = ['view', 'factoryForStatus', 'translateTo', 'translateFrom', 'queue'];
29
30
    protected $statusList = ['approved', 'invoiced', 'shipped', 'delivered', 'canceled', 'frozen'];
31
32
    protected function factoryForStatus($app)
33
    {
34
        foreach ($this->statusList as $status) {
35
            $this->factoryUpdate($app, $status);
36
            $this->factoryList($app, $status);
37
        }
38
    }
39
40
    protected function factoryUpdate($app, $type, Closure $decorator = null)
41
    {
42
        $opts = [
43
            ['key' => 'file'],
44
        ];
45
46
        $this->getApp()->appendCommand('order:update:to:'.$type, 'Move um pedido para a situação ['.$type.']', $opts)
47
            ->addArgument('orderId', InputArgument::REQUIRED, 'Product ID')
48
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $opts, $type, $decorator) {
49
                $list = $app->processInputParameters($opts, $input, $output);
50
                $id = $input->getArgument('orderId');
51 View Code Duplication
                if (!file_exists($list['file'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
                    throw new \InvalidArgumentException('O arquivo ['.$list['file'].'] não existe!');
53
                }
54
                $data = $app->jsonLoadFromFile($list['file']);
55
                $sdk = $app->factorySdk($list);
56
                $manager = $sdk->factoryManager('order');
57
                $order = $sdk->createOrder($data);
58
                $order->setOrderNumber($id)->setOrderStatus($type);
59
60
                if (!empty($decorator)) {
61
                    $order = $decorator($order);
62
                }
63
64
                try {
65
                    $output->writeln('Iniciando mudança de status do pedido #<info>'
66
                    .$id.'</info> => <comment>'.$type.'</comment>');
67
68
                    $operation = $manager->update($order);
69
70
                    if (200 === $operation->getHttpStatusCode()) {
71
                        $output->writeln('<info>Successo!</info>');
72
                    }
73
                } catch (\Exception $e) {
74
                    $app->showException($e, $output, 'Erro na mudança de status');
75
                }
76
            });
77
    }
78
79 View Code Duplication
    protected function view($app)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $this->getApp()->appendCommand('order:view', 'Mostra detalhes de um pedido')
82
            ->addArgument('orderId', InputArgument::REQUIRED, 'Product ID')
83
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
84
                $list = $app->processInputParameters([], $input, $output);
85
                $id = $input->getArgument('orderId');
86
                $p = $app->factorySdk($list)->factoryManager('order')->findById($id);
87
                $app->displayOrder($p, $output);
88
            });
89
    }
90
91
    protected function factoryList($app, $type)
92
    {
93
        $this->getApp()->appendCommand('order:list:'.$type, 'Mostra os pedidos mais recentes em status ['.$type.']')
94
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $type) {
95
                $list = $app->processInputParameters([], $input, $output);
96
                $collection = $app->factorySdk($list)->factoryManager('order')
97
                ->translatorFetch(0, 50, ['orderStatus' => $type]);
98
                $app->displayOrderList($collection, $output);
99
            });
100
    }
101
102
    protected function queue($app)
103
    {
104
        $this->getApp()->appendCommand('order:queue', 'Mostra os pedidos novos e que ainda aguardam processamento')
105 View Code Duplication
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
                $list = $app->processInputParameters([], $input, $output);
107
                $collection = $app->factorySdk($list)->factoryManager('order')->fetchQueue();
108
                $app->displayOrderList($collection, $output);
109
            });
110
    }
111
112 View Code Duplication
    public function translateTo($app)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        $this->getApp()->appendCommand('order:translate:to', 'Exporta o pedido no padrão comum')
115
            ->addArgument('orderId', InputArgument::REQUIRED, 'Order ID')
116
            ->addArgument('filenameOutput', InputArgument::REQUIRED, 'Caminho do arquivo que será gerado')
117
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
118
                $list = $app->processInputParameters([], $input, $output);
119
                $id = $input->getArgument('orderId');
120
                $filenameOutput = $input->getArgument('filenameOutput');
121
                $p = $app->factorySdk($list)->factoryManager('order')->translatorFindById($id);
122
123
                if (empty($p)) {
124
                    return $output->writeln('<error>Pedido não encontrado!</error>');
125
                }
126
127
                return $app->jsonSaveToFile($p->toArray(), $filenameOutput, $output);
128
            });
129
    }
130
131
    public function translateFrom($app)
132
    {
133
        $this->getApp()->appendCommand('order:translate:from', 'Importa o pedido no padrão comum')
134
            ->addArgument('filenameInput', InputArgument::REQUIRED, 'Arquivo json com dados do pedido')
135
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
136
                $list = $app->processInputParameters([], $input, $output);
137
                $foreign = new TranslatorDataCollection($app->jsonLoadFromFile($input->getArgument('filenameInput')));
138
139
                $p = $app->factorySdk($list)->factoryManager('order')->factoryTranslator([
140
                    'foreign' => $foreign,
141
                ]);
142
143
                $app->displayOrder($p->translateFrom(), $output);
144
            });
145
    }
146
}
147