Issues (2)

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/App/App.php (2 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\App;
4
5
use RuntimeException;
6
use Weew\App\Events\AppShutdownEvent;
7
use Weew\App\Events\AppStartedEvent;
8
use Weew\App\Events\ConfigLoadedEvent;
9
use Weew\App\Events\KernelBootedEvent;
10
use Weew\App\Events\KernelInitializedEvent;
11
use Weew\App\Events\KernelShutdownEvent;
12
use Weew\Commander\Commander;
13
use Weew\Commander\ContainerAware\Commander as ContainerAwareCommander;
14
use Weew\Commander\ICommander;
15
use Weew\Config\Config;
16
use Weew\Config\ConfigLoader;
17
use Weew\Config\IConfig;
18
use Weew\Config\IConfigLoader;
19
use Weew\Container\Container;
20
use Weew\Container\IContainer;
21
use Weew\Eventer\ContainerAware\Eventer as ContainerAwareEventer;
22
use Weew\Eventer\Eventer;
23
use Weew\Eventer\IEventer;
24
use Weew\Kernel\ContainerAware\Kernel as ContainerAwareKernel;
25
use Weew\Kernel\IKernel;
26
use Weew\Kernel\Kernel;
27
28
class App implements IApp {
29
    /**
30
     * @var bool
31
     */
32
    protected $started = false;
33
34
    /**
35
     * @var string
36
     */
37
    protected $environment;
38
39
    /**
40
     * @var bool
41
     */
42
    protected $debug;
43
44
    /**
45
     * @var IContainer
46
     */
47
    protected $container;
48
49
    /**
50
     * @var ContainerAwareKernel
51
     */
52
    protected $kernel;
53
54
    /**
55
     * @var IEventer
56
     */
57
    protected $eventer;
58
59
    /**
60
     * @var ICommander
61
     */
62
    protected $commander;
63
64
    /**
65
     * @var IConfig
66
     */
67
    protected $config;
68
69
    /**
70
     * @var IConfigLoader
71
     */
72
    protected $configLoader;
73
74
    /**
75
     * App constructor.
76
     *
77
     * @param string $environment
78
     * @param bool $debug
79
     */
80
    public function __construct($environment = null, $debug = null) {
81
        if ($environment === null) {
82
            $environment = $this->getDefaultEnvironment();
83
        }
84
85
        if ($debug === null) {
86
            $debug = $this->getDefaultDebug();
87
        }
88
89
        $this->setEnvironment($environment);
90
        $this->setDebug($debug);
91
92
        $this->container = new Container();
93
        $this->container->set([App::class, IApp::class], $this);
94
95
        $this->kernel = new ContainerAwareKernel($this->container);
96
        $this->container->set([Kernel::class, IKernel::class], $this->kernel);
97
98
        $this->eventer = new ContainerAwareEventer($this->container);
99
        $this->container->set([Eventer::class, IEventer::class], $this->eventer);
100
101
        $this->commander = new ContainerAwareCommander($this->container);
102
        $this->container->set([Commander::class, ICommander::class], $this->commander);
103
104
        $this->configLoader = new ConfigLoader();
105
    }
106
107
    /**
108
     * Dry run - start and shutdown app.
109
     * This method is not meant to be used as
110
     * the main entry point in to the App.
111
     */
112
    public function run() {
113
        $this->start();
114
        $this->shutdown();
115
    }
116
117
    /**
118
     * Start App.
119
     */
120
    public function start() {
121
        if ($this->started) {
122
            return;
123
        }
124
125
        $this->started = true;
126
127
        $this->getConfigLoader()->setEnvironment($this->getEnvironment());
128
        $this->config = $this->getConfigLoader()->load();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getConfigLoader()->load() of type object<Weew\Config\Config> is incompatible with the declared type object<Weew\Config\IConfig> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
129
        $this->container->set([Config::class, IConfig::class], $this->config);
0 ignored issues
show
array(\Weew\Config\Confi...\Config\IConfig::class) is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
130
        $this->config->set('env', $this->getEnvironment());
131
        $this->config->set('debug', $this->getDebug());
132
        $this->eventer->dispatch(new ConfigLoadedEvent($this->config));
133
134
        $this->kernel->initialize();
135
        $this->eventer->dispatch(new KernelInitializedEvent($this->kernel));
136
        $this->kernel->boot();
137
        $this->eventer->dispatch(new KernelBootedEvent($this->kernel));
138
        $this->eventer->dispatch(new AppStartedEvent($this));
139
    }
140
141
    /**
142
     * Shutdown App.
143
     */
144
    public function shutdown() {
145
        if ( ! $this->started) {
146
            return;
147
        }
148
149
        $this->started = false;
150
151
        $this->kernel->shutdown();
152
        $this->eventer->dispatch(new KernelShutdownEvent($this->kernel));
153
        $this->eventer->dispatch(new AppShutdownEvent($this));
154
    }
155
156
    /**
157
     * Get dependency injection container instance.
158
     *
159
     * @return IContainer
160
     */
161
    public function getContainer() {
162
        return $this->container;
163
    }
164
165
    /**
166
     * Get app kernel instance.
167
     *
168
     * @return IKernel
169
     */
170
    public function getKernel() {
171
        return $this->kernel;
172
    }
173
174
    /**
175
     * Get event bus instance.
176
     *
177
     * @return IEventer
178
     */
179
    public function getEventer() {
180
        return $this->eventer;
181
    }
182
183
    /**
184
     * @return ICommander
185
     */
186
    public function getCommander() {
187
        return $this->commander;
188
    }
189
190
    /**
191
     * @return IConfig
192
     */
193
    public function getConfig() {
194
        if ( ! $this->config instanceof IConfig) {
195
            throw new RuntimeException(
196
                'Config has not been loaded yet. ' .
197
                'Make sure application is started.'
198
            );
199
        }
200
201
        return $this->config;
202
    }
203
204
    /**
205
     * @return string
206
     */
207
    public function getEnvironment() {
208
        return $this->environment;
209
    }
210
211
    /**
212
     * @param string $environment
213
     */
214
    public function setEnvironment($environment) {
215
        if ($this->started) {
216
            throw new RuntimeException(
217
                'Application has already been started ' .
218
                'and environment can not be changed anymore.'
219
            );
220
        }
221
222
        $this->environment = $environment;
223
    }
224
225
    /**
226
     * @return bool
227
     */
228
    public function getDebug() {
229
        return $this->debug;
230
    }
231
232
    /**
233
     * @param bool $debug
234
     */
235
    public function setDebug($debug) {
236
        $this->debug = $debug;
237
    }
238
239
    /**
240
     * Add additional configuration environment.
241
     *
242
     * @param string $name
243
     * @param array $abbreviations
244
     */
245
    public function addEnvironment($name, array $abbreviations) {
246
        $this->getConfigLoader()
247
            ->getEnvironmentDetector()
248
            ->addEnvironmentRule($name, $abbreviations);
249
    }
250
251
    /**
252
     * @return IConfigLoader
253
     */
254
    public function getConfigLoader() {
255
        return $this->configLoader;
256
    }
257
258
    /**
259
     * @return string
260
     */
261
    protected function getDefaultEnvironment() {
262
        return 'dev';
263
    }
264
265
    /**
266
     * @return bool
267
     */
268
    protected function getDefaultDebug() {
269
        return true;
270
    }
271
}
272