Issues (8)

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/SendGridApi.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
namespace Sichikawa\SendgridApiBuilder;
3
4
use Sichikawa\SendgridApiBuilder\Api\Asm;
5
use Sichikawa\SendgridApiBuilder\Api\Attachment;
6
use Sichikawa\SendgridApiBuilder\Api\Content;
7
use Sichikawa\SendgridApiBuilder\Api\CustomArgs;
8
use Sichikawa\SendgridApiBuilder\Api\From;
9
use Sichikawa\SendgridApiBuilder\Api\Headers;
10
use Sichikawa\SendgridApiBuilder\Api\MailSettings;
11
use Sichikawa\SendgridApiBuilder\Api\Personalize;
12
use Sichikawa\SendgridApiBuilder\Api\ReplyTo;
13
use Sichikawa\SendgridApiBuilder\Api\Sections;
14
use Sichikawa\SendgridApiBuilder\Api\TrackingSettings;
15
16
trait SendGridApi
17
{
18
    /**
19
     * @var array
20
     */
21
    private $sg_params = [];
22
23
    /**
24
     * clean for posting to sendgrid
25
     * @param $params
26
     * @return array|mixed
27
     */
28
    public function cleanParams($params)
29
    {
30
        if (is_object($params)) {
31
            $params = json_decode(json_encode($params), true);
32
        }
33
        if (is_array($params)) {
34
            $params = array_filter($params, function ($val) {
35
                return !empty($val);
36
            });
37
38
            $result = [];
39
            foreach ($params as $key => $val) {
40
                if (is_object($val) || is_array($val)) {
41
                    $result[$key] = $this->cleanParams($val);
42
                    continue;
43
                }
44
                $result[$key] = $val;
45
            }
46
            return $result;
47
        }
48
        return $params;
49
    }
50
51
    /**
52
     * @param bool $clean
53
     * @return array
54
     */
55
    public function getSgParams($clean = true)
56
    {
57
        return $clean ? $this->cleanParams($this->sg_params) : $this->sg_params;
58
    }
59
60
    /**
61
     * @param array $sg_params
62
     */
63
    public function setSgParams($sg_params)
64
    {
65
        $this->sg_params = $sg_params;
66
    }
67
68
    /**
69
     * @param array $personalizations
70
     * @return $this
71
     */
72
    public function setPersonalizations($personalizations)
73
    {
74
        $this->sg_params['personalizations'] = $personalizations;
75
        return $this;
76
    }
77
78
    /**
79
     * @param Personalize $personalize
80
     * @return $this
81
     */
82
    public function addPersonalizations(Personalize $personalize)
83
    {
84
        $this->sg_params['personalizations'][] = $personalize;
85
        return $this;
86
    }
87
88
    /**
89
     * @param $email
90
     * @param null $name
91
     * @return $this
92
     */
93
    public function setFrom($email, $name = null)
94
    {
95
        $this->sg_params['from'] = $email instanceof From ? $email : new Api\From($email, $name);
96
        return $this;
97
    }
98
99
    /**
100
     * @param $email
101
     * @param null $name
102
     * @return $this
103
     */
104
    public function setReplyTo($email, $name = null)
105
    {
106
        $this->sg_params['reply_to'] = $email instanceof ReplyTo ? $email : new Api\ReplyTo($email, $name);
107
        return $this;
108
    }
109
110
    /**
111
     * @param string $subject
112
     * @return $this
113
     */
114
    public function setSubject($subject)
115
    {
116
        $this->sg_params['subject'] = $subject;
117
        return $this;
118
    }
119
120
    /**
121
     * @param array $content
122
     * @return $this
123
     */
124
    public function setContent($content)
125
    {
126
        $this->sg_params['content'] = $content;
127
        return $this;
128
    }
129
130
    /**
131
     * @param $type
132
     * @param $value
133
     * @return $this
134
     */
135
    public function addContent($type, $value = null)
136
    {
137
        $this->sg_params['content'][] = $type instanceof Content ? $type : new Content($type, $value);
138
        return $this;
139
    }
140
141
    /**
142
     * @param array $attachments
143
     * @return $this
144
     */
145
    public function setAttachments($attachments)
146
    {
147
        $this->sg_params['attachments'] = $attachments;
148
        return $this;
149
    }
150
151
    /**
152
     * @param Attachment $attachment
153
     * @return $this
154
     */
155
    public function addAttachments(Attachment $attachment)
156
    {
157
        $this->sg_params['attachments'][] = $attachment;
158
        return $this;
159
    }
160
161
    /**
162
     * @param string $id
163
     * @return $this
164
     */
165
    public function setTemplateId($id)
166
    {
167
        $this->sg_params['template_id'] = $id;
168
        return $this;
169
    }
170
171
    /**
172
     * @param Sections $section
173
     * @return $this
174
     */
175
    public function setSection($section)
176
    {
177
        $this->sg_params['section'] = $section;
178
        return $this;
179
    }
180
181
    /**
182
     * @param string $key
183
     * @param string $value
184
     * @return $this
185
     */
186 View Code Duplication
    public function addSection($key, $value)
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...
187
    {
188
189
        if (empty($this->sg_params['section'])) {
190
            $this->sg_params['section'] = new Sections();
191
        }
192
        $this->sg_params['section']->$key = $value;
193
        return $this;
194
    }
195
196
    /**
197
     * @param Headers $headers
198
     * @return $this
199
     */
200
    public function setHeaders($headers)
201
    {
202
        $this->sg_params['headers'] = $headers;
203
        return $this;
204
    }
205
206
    /**
207
     * @param string $key
208
     * @param string $value
209
     * @return $this
210
     */
211 View Code Duplication
    public function addHeaders($key, $value)
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...
212
    {
213
        if (empty($this->sg_params['headers'])) {
214
            $this->sg_params['headers'] = new Headers();
215
        }
216
        $this->sg_params['headers']->$key = $value;
217
        return $this;
218
    }
219
220
    /**
221
     * @param array $categories
222
     * @return $this
223
     */
224
    public function setCategories($categories)
225
    {
226
        $this->sg_params['categories'] = $categories;
227
        return $this;
228
    }
229
230
    /**
231
     * @param string $category
232
     * @return $this
233
     */
234
    public function addCategories($category)
235
    {
236
        $this->sg_params['categories'][] = $category;
237
        return $this;
238
    }
239
240
    /**
241
     * @param CustomArgs $custom_args
242
     * @return $this
243
     */
244
    public function setCustomArgs($custom_args)
245
    {
246
        $this->sg_params['custom_args'] = $custom_args;
247
        return $this;
248
    }
249
250
    /**
251
     * @param string $key
252
     * @param string $val
253
     * @return $this
254
     */
255
    public function addCustomArgs($key, $val)
256
    {
257
        if (empty($this->sg_params['custom_args'])) {
258
            $this->sg_params['custom_args'] = new CustomArgs();
259
        }
260
        $this->sg_params['custom_args'][$key] = $val;
261
        return $this;
262
    }
263
264
    /**
265
     * @param int $send_at
266
     * @return $this
267
     */
268
    public function setSendAt($send_at)
269
    {
270
        $this->sg_params['send_at'] = $send_at;
271
        return $this;
272
    }
273
274
    /**
275
     * @param string $batch_id
276
     * @return $this
277
     */
278
    public function setBatchId($batch_id)
279
    {
280
        $this->sg_params['batch_id'] = $batch_id;
281
        return $this;
282
    }
283
284
    /**
285
     * @param Asm $asm
286
     * @return $this
287
     */
288
    public function setAsm(Asm $asm)
289
    {
290
        $this->sg_params['asm'] = $asm;
291
        return $this;
292
    }
293
294
    /**
295
     * @param string $ip_pool_name
296
     * @return $this
297
     */
298
    public function setIpPoolName($ip_pool_name)
299
    {
300
        $this->sg_params['ip_pool_name'] = $ip_pool_name;
301
        return $this;
302
    }
303
304
    /**
305
     * @param MailSettings $mailSetting
306
     * @return $this
307
     */
308
    public function setMailSettings(MailSettings $mailSetting)
309
    {
310
        $this->sg_params['mail_settings'] = $mailSetting;
311
        return $this;
312
    }
313
314
    /**
315
     * @param TrackingSettings $trackingSettings
316
     * @return $this
317
     */
318
    public function setTrackingSettings(TrackingSettings $trackingSettings)
319
    {
320
        $this->sg_params['tracking_settings'] = $trackingSettings;
321
        return $this;
322
    }
323
}
324