Issues (4)

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.

lib/DataStructure/Sms.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 declare(strict_types=1);
2
3
namespace Fazland\SkebbyRestClient\DataStructure;
4
5
use Fazland\SkebbyRestClient\Constant\ValidityPeriods;
6
use Fazland\SkebbyRestClient\Exception\InvalidDeliveryStartException;
7
use Fazland\SkebbyRestClient\Exception\InvalidValidityPeriodException;
8
9
/**
10
 * Represents an SMS.
11
 *
12
 * @author Massimiliano Braglia <[email protected]>
13
 */
14
class Sms
15
{
16
    /**
17
     * @var string
18
     */
19
    private $sender;
20
21
    /**
22
     * @var string[]
23
     */
24
    private $recipients;
25
26
    /**
27
     * @var string[][]
28
     */
29
    private $recipientVariables;
30
31
    /**
32
     * @var string
33
     */
34
    private $text;
35
36
    /**
37
     * @var string
38
     */
39
    private $userReference;
40
41
    /**
42
     * @var \DateTime
43
     */
44
    private $deliveryStart;
45
46
    /**
47
     * @var \DateInterval
48
     */
49
    private $validityPeriod;
50
51
    /**
52
     * Sms constructor.
53
     */
54 14
    public function __construct()
55
    {
56 14
        $this->recipients = [];
57 14
        $this->recipientVariables = [];
58 14
    }
59
60
    /**
61
     * Creates a new instance of SMS.
62
     *
63
     * @return static
64
     */
65 9
    public static function create(): self
66
    {
67 9
        return new static();
68
    }
69
70
    /**
71
     * Gets the sender.
72
     *
73
     * @return string|null
74
     */
75 8
    public function getSender()
76
    {
77 8
        return $this->sender;
78
    }
79
80
    /**
81
     * Sets the sender.
82
     *
83
     * @param string $sender
84
     *
85
     * @return $this
86
     */
87 1
    public function setSender(string $sender): self
88
    {
89 1
        $this->sender = $sender;
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * Gets the recipients.
96
     *
97
     * @return string[]
98
     */
99 9
    public function getRecipients(): array
100
    {
101 9
        return $this->recipients;
102
    }
103
104
    /**
105
     * Sets the recipients.
106
     *
107
     * @param string[] $recipients
108
     *
109
     * @return $this
110
     */
111 8
    public function setRecipients(array $recipients): self
112
    {
113 8
        $this->recipients = $recipients;
114
115 8
        return $this;
116
    }
117
118
    /**
119
     * Adds a single recipient.
120
     *
121
     * @param string $recipient
122
     *
123
     * @return $this
124
     */
125 6
    public function addRecipient(string $recipient): self
126
    {
127 6
        $this->recipients[] = $recipient;
128
129 6
        return $this;
130
    }
131
132
    /**
133
     * Removes a single recipient.
134
     *
135
     * @param string $recipient
136
     *
137
     * @return $this
138
     */
139 1
    public function removeRecipient(string $recipient): self
140
    {
141 1
        $itemPosition = array_search($recipient, $this->recipients);
142
143 1
        if (false !== $itemPosition) {
144 1
            unset($this->recipients[$itemPosition]);
145
        }
146
147 1
        unset($this->recipientVariables[$recipient]);
148
149 1
        return $this;
150
    }
151
152
    /**
153
     * Whether the current sms has or not recipients.
154
     *
155
     * @return bool
156
     */
157 9
    public function hasRecipients(): bool
158
    {
159 9
        return ! empty($this->recipients);
160
    }
161
162
    /**
163
     * Gets the recipient variables.
164
     *
165
     * @return string[][]
166
     */
167 10
    public function getRecipientVariables(): array
168
    {
169 10
        return $this->recipientVariables;
170
    }
171
172
    /**
173
     * Sets the recipient variables for the recipient specified.
174
     *
175
     * @param string   $recipient
176
     * @param string[] $recipientVariables
177
     *
178
     * @return $this
179
     */
180 1
    public function setRecipientVariables(string $recipient, array $recipientVariables): self
181
    {
182 1
        $this->recipientVariables[$recipient] = $recipientVariables;
183
184 1
        return $this;
185
    }
186
187
    /**
188
     * Adds a single recipient variable for the specified recipient.
189
     *
190
     * @param string $recipient
191
     * @param string $recipientVariable
192
     * @param string $recipientVariableValue
193
     *
194
     * @return $this
195
     */
196 5
    public function addRecipientVariable(
197
        string $recipient,
198
        string $recipientVariable,
199
        string $recipientVariableValue
200
    ): self {
201 5
        if (! isset($this->recipientVariables[$recipient])) {
202 5
            $this->recipientVariables[$recipient] = [];
203
        }
204
205 5
        $this->recipientVariables[$recipient][$recipientVariable] = $recipientVariableValue;
206
207 5
        return $this;
208
    }
209
210
    /**
211
     * Removes the recipient variable for the recipient specified.
212
     *
213
     * @param string $recipient
214
     * @param string $recipientVariable
215
     *
216
     * @return $this
217
     */
218 1
    public function removeRecipientVariable(string $recipient, string $recipientVariable): self
219
    {
220 1
        unset($this->recipientVariables[$recipient][$recipientVariable]);
221
222 1
        return $this;
223
    }
224
225
    /**
226
     * Whether the current sms has or not recipient variables.
227
     *
228
     * @return bool
229
     */
230 8
    public function hasRecipientVariables(): bool
231
    {
232 8
        return ! empty($this->recipientVariables);
233
    }
234
235
    /**
236
     * Clears the recipient variables.
237
     *
238
     * @return $this
239
     */
240 8
    public function clearRecipientVariables(): self
241
    {
242 8
        $this->recipientVariables = [];
243
244 8
        return $this;
245
    }
246
247
    /**
248
     * Gets the text.
249
     *
250
     * @return string
251
     */
252 8
    public function getText()
253
    {
254 8
        return $this->text;
255
    }
256
257
    /**
258
     * Sets the text.
259
     *
260
     * @param string $text
261
     *
262
     * @return $this
263
     */
264 9
    public function setText(string $text): self
265
    {
266 9
        $this->text = $text;
267
268 9
        return $this;
269
    }
270
271
    /**
272
     * Gets the user reference.
273
     *
274
     * @return string
275
     */
276 8
    public function getUserReference()
277
    {
278 8
        return $this->userReference;
279
    }
280
281
    /**
282
     * Sets the user reference.
283
     *
284
     * @param string $userReference
285
     *
286
     * @return $this
287
     */
288 1
    public function setUserReference(string $userReference): self
289
    {
290 1
        $this->userReference = $userReference;
291
292 1
        return $this;
293
    }
294
295
    /**
296
     * Gets the delivery start.
297
     *
298
     * @return \DateTimeInterface
299
     */
300 8
    public function getDeliveryStart()
301
    {
302 8
        return $this->deliveryStart;
303
    }
304
305
    /**
306
     * @param \DateTimeInterface|null $deliveryStart
307
     *
308
     * @return $this
309
     *
310
     * @throws InvalidDeliveryStartException
311
     */
312 3
    public function setDeliveryStart(\DateTimeInterface $deliveryStart = null)
313
    {
314 3
        if (null !== $deliveryStart && $deliveryStart < date_create_from_format('U', (string) time())) {
315 1
            throw new InvalidDeliveryStartException();
316
        }
317
318 2
        $this->deliveryStart = $deliveryStart;
0 ignored issues
show
Documentation Bug introduced by
It seems like $deliveryStart can also be of type object<DateTimeInterface>. However, the property $deliveryStart is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
319
320 2
        return $this;
321
    }
322
323
    /**
324
     * Gets the validity period.
325
     *
326
     * @return \DateInterval
327
     */
328 8
    public function getValidityPeriod()
329
    {
330 8
        return $this->validityPeriod;
331
    }
332
333
    /**
334
     * Sets the validity period.
335
     *
336
     * @param \DateInterval|null $validityPeriod
337
     *
338
     * @return $this
339
     *
340
     * @throws InvalidValidityPeriodException
341
     */
342 3
    public function setValidityPeriod(\DateInterval $validityPeriod = null): self
343
    {
344 3
        if (null !== $validityPeriod &&
345 3
            ($validityPeriod->i < ValidityPeriods::MIN || $validityPeriod->i > ValidityPeriods::MAX)
346
        ) {
347 1
            throw new InvalidValidityPeriodException();
348
        }
349
350 2
        $this->validityPeriod = $validityPeriod;
351
352 2
        return $this;
353
    }
354
}
355