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/Logger.php (1 issue)

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 Logger
5
{
6
    use Environment\OptionalTrait {
7
        getEnvironment as getEnvironmentTrait;
8
    }
9
    use Config\OptionalTrait;
10
    /**
11
     * Detailed debug information
12
     */
13
    const DEBUG = \Monolog\Logger::DEBUG;
14
15
    /**
16
     * Interesting events
17
     *
18
     * Examples: User logs in, SQL logs.
19
     */
20
    const INFO = \Monolog\Logger::INFO;
21
22
    /**
23
     * Uncommon events
24
     */
25
    const NOTICE = \Monolog\Logger::NOTICE;
26
27
    /**
28
     * Exceptional occurrences that are not errors
29
     *
30
     * Examples: Use of deprecated APIs, poor use of an API,
31
     * undesirable things that are not necessarily wrong.
32
     */
33
    const WARNING = \Monolog\Logger::WARNING;
34
35
    /**
36
     * Runtime errors
37
     */
38
    const ERROR = \Monolog\Logger::ERROR;
39
40
    /**
41
     * Critical conditions
42
     *
43
     * Example: Application component unavailable, unexpected exception.
44
     */
45
    const CRITICAL = \Monolog\Logger::CRITICAL;
46
47
    /**
48
     * Action must be taken immediately
49
     *
50
     * Example: Entire website down, database unavailable, etc.
51
     * This should trigger the SMS alerts and wake you up.
52
     */
53
    const ALERT = \Monolog\Logger::ALERT;
54
55
    /**
56
     * Urgent alert.
57
     */
58
    const EMERGENCY = \Monolog\Logger::EMERGENCY;
59
60
61
    private $instances = array();
62
    /**
63
     * @var Request
64
     */
65
    private $request;
66
67
68
    protected $factory;
69
70
    /**
71
     * @return Logger\Factory
72
     */
73 2
    public function getFactory()
74
    {
75 2
        if (!$this->factory) {
76 2
            $this->factory = Logger\Factory::getInstance();
77
        }
78 2
        return $this->factory;
79
    }
80
81
    /**
82
     * @param Logger\Factory $factory
83
     * @return $this
84
     */
85 1
    public function setFactory(Logger\Factory $factory)
86
    {
87 1
        $this->factory = $factory;
88 1
        return $this;
89
    }
90
91
    /**
92
     * @param string $instanceName
93
     * @return Logger\Channel
94
     */
95 2
    public function get($instanceName)
96
    {
97 2
        $instanceName = (string)$instanceName;
98 2
        if (!isset($this->instances[$instanceName])) {
99 1
            $channel = $this->getFactory()->getChannel($instanceName);
100 1
            $channel->setConfig($this->getConfig())->setEnvironment($this->getEnvironment());
101 1
            $this->instances[$instanceName] = $channel;
102
        }
103 2
        return $this->instances[$instanceName];
104
    }
105
106
    /**
107
     * @param Logger\Channel $logger
108
     * @param string $instanceName
109
     * @return $this
110
     */
111 2
    public function set(Logger\Channel $logger, $instanceName)
112
    {
113 2
        $instanceName = (string)$instanceName;
114 2
        if (!is_null($logger) && !is_null($instanceName)) {
115 2
            $this->instances[$instanceName] = $logger;
116
        }
117 2
        return $this;
118
    }
119
120
    /**
121
     * Define HTTP request object
122
     * @param Request $request
123
     * @return $this
124
     */
125 3
    public function setRequest(Request $request)
126
    {
127 3
        $this->request = $request;
128 3
        return $this;
129
    }
130
131
    /**
132
     * Retrieve defined HTTP request object
133
     * @return Request
134
     * @throws \LogicException if no request has been set
135
     */
136 2
    public function getRequest()
137
    {
138 2
        if (!$this->request) {
139 1
            throw new \LogicException('Request is not defined');
140
        }
141 1
        return $this->request;
142
    }
143
144
    /**
145
     * @return Environment
146
     */
147 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...
148
    {
149 2
        if (!$this->hasEnvironment()) {
150 2
            $environment = Environment::getInstance();
151 2
            $this->setEnvironment($environment->setConfig($this->getConfig()));
152
        }
153 2
        return $this->getEnvironmentTrait();
154
    }
155
156
    /**
157
     * Add log Record
158
     * @param string $channel
159
     * @param int $level
160
     * @param string $message
161
     * @param array $context
162
     * @return bool
163
     */
164 1
    public function log($channel, $level, $message, array $context = array())
165
    {
166 1
        $channel = (string)$channel;
167 1
        $message = (string)$message;
168 1
        $level = (int)($level <= 0 ? self::ALERT : $level);
169 1
        $channelType = $this->get($channel);
170 1
        if ($channelType->getName() === Logger\Channel\Standard::NAME) {
171 1
            $message = "[Channel $channel] $message";
172
        }
173 1
        return $channelType->addRecord((int)$level, $message, (array)$context);
174
    }
175
}
176