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/Builder/NotifierBuilder.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
declare(strict_types = 1);
3
4
5
namespace SM\AirbrakeBundle\Builder;
6
7
use Airbrake\Notifier;
8
use SM\AirbrakeBundle\Enum\AirbrakeDefaultEnum;
9
use SM\AirbrakeBundle\Exception\AirbrakeConfigurationException;
10
11
/**
12
 * Handles the construction of Airbrake notifiers.
13
 *
14
 * @package SM\AirbrakeBundle\Builder
15
 * @author  Petre Pătrașc <[email protected]>
16
 */
17
class NotifierBuilder implements BuilderInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $projectKey;
23
24
    /**
25
     * @var string
26
     */
27
    protected $projectId;
28
29
    /**
30
     * @var string
31
     */
32
    protected $host;
33
34
    /**
35
     * @var string
36
     */
37
    protected $httpClient;
38
39
    /**
40
     * @var string
41
     */
42
    protected $rootDirectory;
43
44
    /**
45
     * @var array
46
     */
47
    protected $ignoredExceptions;
48
49
    /**
50
     * @var string
51
     */
52
    protected $environment;
53
54
    /**
55
     * @var string
56
     */
57
    protected $appVersion;
58
59
    /**
60
     * NotifierBuilder constructor.
61
     */
62 20
    public function __construct()
63
    {
64 20
        $this->clear();
65 20
    }
66
67 8
    public function withProjectKey(string $projectKey): NotifierBuilder
68
    {
69 8
        if (empty(trim($projectKey))) {
70 2
            throw new AirbrakeConfigurationException('Project API key cannot be empty');
71
        }
72
73 6
        $this->projectKey = $projectKey;
74
75 6
        return $this;
76
    }
77
78 8
    public function withProjectId(string $projectId): NotifierBuilder
79
    {
80 8
        if (empty(trim($projectId))) {
81 3
            throw new AirbrakeConfigurationException('Project ID cannot be empty');
82
        }
83
84 5
        $this->projectId = $projectId;
85
86 5
        return $this;
87
    }
88
89 7 View Code Duplication
    public function withHost(string $host): NotifierBuilder
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...
90
    {
91 7
        if (empty(trim($host))) {
92 2
            throw new AirbrakeConfigurationException('Host cannot be empty');
93
        }
94
95 5
        $this->host = $host;
96
97 5
        return $this;
98
    }
99
100 6
    public function withHttpClient(string $httpClient): NotifierBuilder
101
    {
102 6
        if (empty(trim($httpClient))) {
103 2
            throw new AirbrakeConfigurationException('HTTP client cannot be empty');
104
        }
105
106 4
        $this->httpClient = $httpClient;
107
108 4
        return $this;
109
    }
110
111 7
    public function withRootDirectory(string $rootDirectory): NotifierBuilder
112
    {
113 7
        if (empty(trim($rootDirectory))) {
114 2
            throw new AirbrakeConfigurationException('Root directory cannot be empty');
115
        }
116
117 5
        $this->rootDirectory = $rootDirectory;
118
119 5
        return $this;
120
    }
121
122 5
    public function withIgnoredExceptions(array $ignoredExceptions = []): NotifierBuilder
123
    {
124 5
        $this->ignoredExceptions = $ignoredExceptions;
125
126 5
        return $this;
127
    }
128
129 7 View Code Duplication
    public function withEnvironment(string $environment): NotifierBuilder
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...
130
    {
131 7
        if (empty(trim($environment))) {
132 2
            throw new AirbrakeConfigurationException('Environment cannot be empty');
133
        }
134
135 5
        $this->environment = $environment;
136
137 5
        return $this;
138
    }
139
140 7
    public function withAppVersion(string $appVersion): NotifierBuilder
141
    {
142 7
        if (empty(trim($appVersion))) {
143 2
            throw new AirbrakeConfigurationException('App version cannot be empty');
144
        }
145
146 5
        $this->appVersion = $appVersion;
147
148 5
        return $this;
149
    }
150
151
    /**
152
     * @inheritDoc
153
     */
154 5
    public function build(): Notifier
155
    {
156 5
        $notifierInstance = new Notifier([
157 5
            'projectId'     => $this->projectId,
158 5
            'projectKey'    => $this->projectKey,
159 5
            'host'          => $this->host,
160 5
            'rootDirectory' => $this->rootDirectory,
161 5
            'httpClient'    => $this->httpClient,
162 5
            'environment'   => $this->environment,
163 5
            'appVersion'    => $this->appVersion,
164
        ]);
165
166 5
        $this->addFilteredExceptions($notifierInstance);
167 5
        $this->clear();
168
169 5
        return $notifierInstance;
170
    }
171
172
    /**
173
     * @inheritDoc
174
     */
175 20
    public function clear()
176
    {
177 20
        $this->projectKey        = AirbrakeDefaultEnum::PROJECT_KEY;
178 20
        $this->projectId         = AirbrakeDefaultEnum::PROJECT_ID;
179 20
        $this->host              = AirbrakeDefaultEnum::HOST;
180 20
        $this->httpClient        = AirbrakeDefaultEnum::HTTP_CLIENT;
181 20
        $this->ignoredExceptions = AirbrakeDefaultEnum::IGNORED_EXCEPTIONS;
182 20
        $this->rootDirectory     = AirbrakeDefaultEnum::ROOT_DIRECTORY;
183 20
        $this->environment       = AirbrakeDefaultEnum::ENVIRONMENT;
184 20
        $this->appVersion        = AirbrakeDefaultEnum::APP_VERSION;
185 20
    }
186
187
    /**
188
     * Add filtered exceptions to the notifier.
189
     *
190
     * @param Notifier $notifierInstance
191
     */
192 5
    protected function addFilteredExceptions(Notifier $notifierInstance)
193
    {
194 5
        if (false === empty($this->ignoredExceptions)) {
195 5
            $ignoredExceptions = $this->ignoredExceptions;
196 5
            $notifierInstance->addFilter(function ($notice) use ($ignoredExceptions) {
197
                foreach ($ignoredExceptions as $exceptionClass) {
198
                    if ($notice['errors'][0]['type'] === $exceptionClass) {
199
                        return null;
200
                    }
201
                }
202
203
                return $notice;
204 5
            });
205
        }
206 5
    }
207
}
208