Issues (27)

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/Weew/Console/Input.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
namespace Weew\Console;
4
5
use Weew\ConsoleArguments\Command;
6
use Weew\ConsoleArguments\Exceptions\ArgumentNotFoundException;
7
use Weew\ConsoleArguments\Exceptions\OptionNotFoundException;
8
use Weew\ConsoleArguments\ICommand;
9
10
class Input implements IInput {
11
    /**
12
     * @var ICommand
13
     */
14
    protected $command;
15
16
    /**
17
     * @var int
18
     */
19
    protected $inputVerbosity;
20
21
    /**
22
     * @var resource
23
     */
24
    protected $inputStream;
25
26
    /**
27
     * Input constructor.
28
     *
29
     * @param ICommand $command
30
     */
31
    public function __construct(ICommand $command = null) {
32
        if ( ! $command instanceof ICommand) {
33
            $command = new Command();
34
        }
35
36
        $this->command = $command;
37
        $this->setInputVerbosity(InputVerbosity::NORMAL);
38
    }
39
40
    /**
41
     * @param string $name
42
     * @param null $default
43
     *
44
     * @return mixed|null
45
     */
46
    public function getArgument($name, $default = null) {
47
        try {
48
            $argument = $this->getCommand()->findArgument($name);
49
            $value = $argument->getValue();
50
51
            if ($value === null) {
52
                $value = $default;
53
            }
54
55
            return $value;
56
        } catch (ArgumentNotFoundException $ex) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
57
58
        return $default;
59
    }
60
61
    /**
62
     * @param string $name
63
     * @param mixed $value
64
     */
65
    public function setArgument($name, $value) {
66
        $argument = $this->getCommand()->findArgument($name);
67
        $argument->setValue($value);
68
    }
69
70
    /**
71
     * @param string $name
72
     *
73
     * @return bool
74
     */
75
    public function hasArgument($name) {
76
        try {
77
            $argument = $this->getCommand()->findArgument($name);
78
79
            return $argument->hasValue();
80
        } catch (ArgumentNotFoundException $ex) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
81
82
        return false;
83
    }
84
85
    /**
86
     * @param $nameOrAlias
87
     * @param null $default
88
     *
89
     * @return mixed|null
90
     */
91
    public function getOption($nameOrAlias, $default = null) {
92
        try {
93
            $option = $this->getCommand()->findOption($nameOrAlias);
94
            $value = $option->getValue();
95
96
            if ($value === null) {
97
                $value = $default;
98
            }
99
100
            return $value;
101
        } catch (OptionNotFoundException $ex) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
102
103
        return $default;
104
    }
105
106
    /**
107
     * @param string $nameOrAlias
108
     * @param mixed $value
109
     */
110
    public function setOption($nameOrAlias, $value) {
111
        $option = $this->getCommand()->findOption($nameOrAlias);
112
        $option->setValue($value);
113
    }
114
115
    /**
116
     * @param string $nameOrAlias
117
     *
118
     * @return bool
119
     */
120
    public function hasOption($nameOrAlias) {
121
        try {
122
            $option = $this->getCommand()->findOption($nameOrAlias);
123
124
            return $option->hasValue();
125
        } catch (OptionNotFoundException $ex) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
126
127
        return false;
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function readLine() {
134
        if ( ! $this->is(InputVerbosity::SILENT)) {
135
            return trim(fgets($this->getInputStream()));
136
        }
137
138
        return '';
139
    }
140
141
    /**
142
     * @return string
143
     */
144
    public function readChar() {
145
        if ( ! $this->is(InputVerbosity::SILENT)) {
146
            return fgetc($this->getInputStream());
147
        }
148
149
        return '';
150
    }
151
152
    /**
153
     * @return ICommand
154
     */
155
    public function getCommand() {
156
        return $this->command;
157
    }
158
159
    /**
160
     * @param ICommand $command
161
     */
162
    public function setCommand(ICommand $command) {
163
         $this->command = $command;
164
    }
165
166
    /**
167
     * @return int
168
     */
169
    public function getInputVerbosity() {
170
        return $this->inputVerbosity;
171
    }
172
173
    /**
174
     * @param int $inputVerbosity
175
     *
176
     * @see InputVerbosity
177
     */
178
    public function setInputVerbosity($inputVerbosity) {
179
        $this->inputVerbosity = $inputVerbosity;
180
    }
181
182
    /**
183
     * @param $options
184
     *
185
     * @return bool
186
     */
187
    protected function is($options) {
188
        return ($this->getInputVerbosity() & $options) === $options;
189
    }
190
191
192
    /**
193
     * @return resource
194
     */
195
    protected function getInputStream() {
196
        if ($this->inputStream === null) {
197
            $this->inputStream = fopen('php://stdin', 'r');
198
        }
199
200
        return $this->inputStream;
201
    }
202
}
203