Issues (9)

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/Support/Commander.php (3 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
namespace Bmatovu\ArtisanGui\Support;
4
5
use Illuminate\Contracts\Console\Kernel;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputDefinition;
9
use Symfony\Component\Console\Input\InputOption;
10
11
/**
12
 * @see \Symfony\Component\Console\Descriptor\JsonDescriptor
13
 */
14
class Commander
15
{
16
    const GLOBAL_NAMESPACE = 'laravel';
17
18
    private $kernel;
19
    private $namespace;
20
    private $namespaces;
21
    private $commands;
22
    private $aliases;
23
    private $definition;
24
25 1
    public function __construct(Kernel $kernel)
26
    {
27 1
        $this->kernel = $kernel;
28
29 1
        $this->loadApplicationDefinition();
30
31 1
        $this->loadNamespacesAndCommands();
32 1
    }
33
34
    public function getKernel()
35
    {
36
        return $this->kernel;
37
    }
38
39
    public function getNamespace()
40
    {
41
        return $this->namespace;
42
    }
43
44 1
    public function getNamespaces()
45
    {
46 1
        return $this->namespaces;
47
    }
48
49 1
    public function getCommands()
50
    {
51 1
        return $this->commands;
52
    }
53
54
    public function getAliases()
55
    {
56
        return $this->aliases;
57
    }
58
59 1
    public function getDefinition()
60
    {
61 1
        return $this->definition;
62
    }
63
64 1
    protected function extractNamespace(string $name, int $limit = null)
65
    {
66 1
        $parts = explode(':', $name, -1);
67
68 1
        return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit));
69
    }
70
71 1
    protected function sortCommands(array $commands): array
72
    {
73 1
        $namespacedCommands = [];
74 1
        $globalCommands = [];
75 1
        $sortedCommands = [];
76 1
        foreach ($commands as $name => $command) {
77 1
            $key = $this->extractNamespace($name, 1);
78 1
            if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) {
79 1
                $globalCommands[$name] = $command;
80
            } else {
81 1
                $namespacedCommands[$key][$name] = $command;
82
            }
83
        }
84
85 1
        if ($globalCommands) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $globalCommands of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
86 1
            ksort($globalCommands);
87 1
            $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands;
88
        }
89
90 1
        if ($namespacedCommands) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $namespacedCommands of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
91 1
            ksort($namespacedCommands);
92 1
            foreach ($namespacedCommands as $key => $commandsSet) {
93 1
                ksort($commandsSet);
94 1
                $sortedCommands[$key] = $commandsSet;
95
            }
96
        }
97
98 1
        return $sortedCommands;
99
    }
100
101
    /**
102
     * @see \Symfony\Component\Console\Descriptor\ApplicationDescription::inspectApplication
103
     */
104 1
    public function loadNamespacesAndCommands()
105
    {
106 1
        $this->commands = [];
107 1
        $this->namespaces = [];
108
109 1
        $all = $this->kernel->all($this->namespace);
0 ignored issues
show
The call to Kernel::all() has too many arguments starting with $this->namespace.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
110
111 1
        foreach ($this->sortCommands($all) as $namespace => $commands) {
112 1
            $names = [];
113
114
            /** @var Command $command */
115 1
            foreach ($commands as $name => $command) {
116
                // if (!$command->getName() || (!$this->showHidden && $command->isHidden())) {
117 1
                if (! $command->getName()) {
118
                    continue;
119
                }
120
121 1
                if ($command->getName() === $name) {
122 1
                    $this->commands[$name] = $this->getCommandData($command);
123
                } else {
124
                    $this->aliases[$name] = $command;
125
                }
126
127 1
                $names[] = $name;
128
            }
129
130
            // $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names];
131 1
            $this->namespaces[$namespace] = $names;
132
        }
133 1
    }
134
135 1
    protected function loadApplicationDefinition()
136
    {
137 1
        $this->definition = [];
138
139 1
        $commands = $this->kernel->all();
140
141 1
        $command = array_values($commands)[0];
142
143 1
        $application = $command->getApplication();
144
145 1
        $this->definition = $this->getInputDefinitionData($application->getDefinition());
146
147
        // $this->arguments = $this->getInputDefinitionArguments($application->getDefinition());
148
149
        // $this->options = $this->getInputDefinitionOptions($application->getDefinition());
150 1
    }
151
152 1
    protected function getInputArgumentData(InputArgument $argument): array
153
    {
154
        return [
155 1
            'name' => $argument->getName(),
156 1
            'is_required' => $argument->isRequired(),
157 1
            'is_array' => $argument->isArray(),
158 1
            'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
159 1
            'value' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
160
        ];
161
    }
162
163 1
    protected function getInputOptionData(InputOption $option): array
164
    {
165
        return [
166 1
            'name' => '--'.$option->getName(),
167 1
            'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '',
168 1
            'is_flag' => ! $option->acceptValue(),
169 1
            'is_required' => $option->isValueRequired(),
170 1
            'is_array' => $option->isArray(),
171 1
            'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()),
172 1
            'value' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(),
173
        ];
174
    }
175
176 1
    protected function getInputDefinitionData(InputDefinition $definition): array
177
    {
178 1
        $inputArguments = [];
179 1
        foreach ($definition->getArguments() as $name => $argument) {
180 1
            $inputArguments[$name] = $this->getInputArgumentData($argument);
181
        }
182
183 1
        $inputOptions = [];
184 1
        foreach ($definition->getOptions() as $name => $option) {
185 1
            $inputOptions[$name] = $this->getInputOptionData($option);
186
        }
187
188 1
        return ['arguments' => $inputArguments, 'options' => $inputOptions];
189
    }
190
191 1
    protected function getInputDefinitionArguments(InputDefinition $definition): array
192
    {
193 1
        $inputArguments = [];
194 1
        foreach ($definition->getArguments() as $name => $argument) {
195 1
            $inputArguments[$name] = $this->getInputArgumentData($argument);
196
        }
197
198 1
        return $inputArguments;
199
    }
200
201 1
    protected function getInputDefinitionOptions(InputDefinition $definition): array
202
    {
203 1
        $inputOptions = [];
204 1
        foreach ($definition->getOptions() as $name => $option) {
205 1
            $inputOptions[$name] = $this->getInputOptionData($option);
206
        }
207
208 1
        return $inputOptions;
209
    }
210
211 1
    protected function getCommandData(Command $command): array
212
    {
213
        // $command->mergeApplicationDefinition(false);
214
215
        return [
216 1
            'name' => $command->getName(),
217 1
            'synopsis' => $command->getSynopsis(false),
218
            // 'usages' => $command->getUsages(),
219
            // 'aliases' => $command->getAliases(),
220 1
            'description' => $command->getDescription(),
221 1
            'help' => $command->getProcessedHelp(),
222
            // 'definition' => $this->getInputDefinitionData($command->getDefinition()),
223 1
            'arguments' => $this->getInputDefinitionArguments($command->getDefinition()),
224 1
            'options' => $this->getInputDefinitionOptions($command->getDefinition()),
225 1
            'hidden' => $command->isHidden(),
226
        ];
227
    }
228
}
229