Issues (183)

Security Analysis    not enabled

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/Bootstrap.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
namespace FMUP;
3
4
class Bootstrap implements Environment\OptionalInterface, Sapi\OptionalInterface, Logger\LoggerInterface
5
{
6
    use Environment\OptionalTrait {
7
        getEnvironment as getEnvironmentTrait;
8
        setEnvironment as setEnvironmentTrait;
9
    }
10
    use Sapi\OptionalTrait;
11
    use Config\RequiredTrait;
12
    use Logger\LoggerTrait {
13
        getLogger as getLoggerTrait;
14
        setLogger as setLoggerTrait;
15
    }
16
17
    private $isErrorHandlerRegistered = false;
18
    private $request;
19
    private $session;
20
    private $flashMessenger;
21
    private $isWarmed;
22
    /**
23
     * @var Cookie
24
     */
25
    private $cookie;
26
27
    /**
28
     * Prepare needed configuration in bootstrap.
29
     *
30
     * There is no need to warm up DB connection but it could be configured
31
     *
32
     * @return $this
33
     */
34 1
    public function warmUp()
35
    {
36 1
        if (!$this->isWarmed()) {
37 1
            $this->defineTimezone();
38 1
            $this->getLogger();
39 1
            $this->initHelperDb();
40 1
            $this->getEnvironment();
41
            //$this->registerErrorHandler(); //@todo activation of this might be very useful
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42 1
            $this->setIsWarmed();
43
        }
44 1
        return $this;
45
    }
46
47
    /**
48
     * Define default timezone
49
     * @return $this
50
     * @codeCoverageIgnore
51
     */
52
    protected function defineTimezone()
53
    {
54
        date_default_timezone_set("Europe/Paris");
55
        return $this;
56
    }
57
58
    /**
59
     * Initialize Config in helper db
60
     * @return $this
61
     */
62 1
    private function initHelperDb()
63
    {
64 1
        Db\Manager::getInstance()
65 1
            ->setConfig($this->getConfig())//@todo find a better solution
66 1
            ->setLogger($this->getLogger());
67 1
        return $this;
68
    }
69
70
    /**
71
     * @return Session
72
     */
73 2
    public function getSession()
74
    {
75 2
        if (!$this->session) {
76 1
            $this->session = Session::getInstance();
77
        }
78 2
        return $this->session;
79
    }
80
81
    /**
82
     * Define session component
83
     * @param Session $session
84
     * @return $this
85
     */
86 2
    public function setSession(Session $session)
87
    {
88 2
        $this->session = $session;
89 2
        return $this;
90
    }
91
92
    /**
93
     * Return logger
94
     * @return Logger
95
     */
96 2
    public function getLogger()
97
    {
98 2
        if (!$this->hasLogger()) {
99 2
            $this->setLogger(
100 2
                (new Logger())
101 2
                    ->setRequest($this->getRequest())
102 2
                    ->setConfig($this->getConfig())
103 2
                    ->setEnvironment($this->getEnvironment())
104
            );
105
        }
106 2
        return $this->getLoggerTrait();
107
    }
108
109
    /**
110
     * Define logger
111
     * @param Logger $logger
112
     * @return $this
113
     */
114 2
    public function setLogger(Logger $logger)
115
    {
116 2
        if (!$logger->hasEnvironment()) {
117 1
            $logger->setEnvironment($this->getEnvironment());
118
        }
119 2
        $this->setLoggerTrait($logger);
120 2
        return $this;
121
    }
122
123 1
    public function registerErrorHandler()
124
    {
125 1
        if (!$this->isErrorHandlerRegistered) {
126 1
            \Monolog\ErrorHandler::register($this->getLogger()->get(\FMUP\Logger\Channel\System::NAME)->getLogger());
127 1
            $this->isErrorHandlerRegistered = true;
128
        }
129 1
        return $this;
130
    }
131
132
    /**
133
     * Define HTTP request object
134
     * @param Request $request
135
     * @return $this
136
     */
137 1
    public function setRequest(Request $request)
138
    {
139 1
        $this->request = $request;
140 1
        return $this;
141
    }
142
143
    /**
144
     * Retrieve defined HTTP request object
145
     * @return Request
146
     * @throws \LogicException if no request has been set
147
     */
148 2
    public function getRequest()
149
    {
150 2
        if (!$this->hasRequest()) {
151 1
            throw new \LogicException('Request is not defined');
152
        }
153 1
        return $this->request;
154
    }
155
156
    /**
157
     * Check if request is defined
158
     * @return bool
159
     */
160 2
    public function hasRequest()
161
    {
162 2
        return !is_null($this->request);
163
    }
164
165
    /**
166
     * Get flashMessenger
167
     * @return \FMUP\FlashMessenger
168
     */
169 1
    public function getFlashMessenger()
170
    {
171 1
        if ($this->flashMessenger === null) {
172 1
            $this->flashMessenger = FlashMessenger::getInstance();
173
        }
174 1
        return $this->flashMessenger;
175
    }
176
177
    /**
178
     * @param FlashMessenger $flashMessenger
179
     * @return $this
180
     */
181 1
    public function setFlashMessenger(FlashMessenger $flashMessenger)
182
    {
183 1
        $this->flashMessenger = $flashMessenger;
184 1
        return $this;
185
    }
186
187
    /**
188
     * @return bool
189
     */
190 1
    public function isWarmed()
191
    {
192 1
        return (bool)$this->isWarmed;
193
    }
194
195
    /**
196
     * @return $this
197
     */
198 1
    public function setIsWarmed()
199
    {
200 1
        $this->isWarmed = true;
201 1
        return $this;
202
    }
203
204
    /**
205
     * @return Environment
206
     */
207 2 View Code Duplication
    public function getEnvironment()
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...
208
    {
209 2
        if (!$this->hasEnvironment()) {
210 2
            $environment = Environment::getInstance();
211 2
            $environment->setConfig($this->getConfig());
212 2
            $this->setEnvironmentTrait($environment);
213
        }
214 2
        return $this->getEnvironmentTrait();
215
    }
216
217
    /**
218
     * @param Environment $environment
219
     * @return $this
220
     */
221 1
    public function setEnvironment(Environment $environment = null)
222
    {
223 1
        if (!$environment->hasConfig()) {
224 1
            $environment->setConfig($this->getConfig());
0 ignored issues
show
It seems like $environment is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
225
        }
226 1
        $this->setEnvironmentTrait($environment);
227 1
        return $this;
228
    }
229
230
    /**
231
     * Retriever Cookie component
232
     * @return Cookie
233
     */
234 1
    public function getCookie()
235
    {
236 1
        if (!$this->cookie) {
237 1
            $this->cookie = Cookie::getInstance();
238
        }
239 1
        return $this->cookie;
240
    }
241
242
    /**
243
     * Define cookie component
244
     * @param Cookie $cookie
245
     * @return $this
246
     */
247 1
    public function setCookie(Cookie $cookie)
248
    {
249 1
        $this->cookie = $cookie;
250 1
        return $this;
251
    }
252
}
253