Issues (7)

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/Payloads/Payload.php (5 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
3
namespace BrightComponents\Common\Payloads;
4
5
use ArrayAccess;
6
use JsonSerializable;
7
use Illuminate\Contracts\Support\Jsonable;
8
use Illuminate\Contracts\Support\Arrayable;
9
use BrightComponents\Common\Payloads\Contracts\PayloadContract;
10
11
class Payload implements PayloadContract, ArrayAccess, JsonSerializable, Jsonable, Arrayable
12
{
13
    /** @var int */
14
    private $status;
15
16
    /** @var mixed */
17
    private $output;
18
19
    /** @var array */
20
    private $messages = [];
21
22
    /** @var string|null */
23
    private $outputWrapper = null;
24
25
    /** @var string */
26
    private $messagesWrapper = 'messages';
27
28
    /**
29
     * Set the Payload status.
30
     *
31
     * @param  int  $status
32
     *
33
     * @return $this
34
     */
35
    public function setStatus($status)
36
    {
37
        return tap($this, function ($instance) use ($status) {
38
            $instance->status = $status;
39
        });
40
    }
41
42
    /**
43
     * Get the status of the payload.
44
     *
45
     * @return int
46
     */
47
    public function getStatus()
48
    {
49
        return $this->status;
50
    }
51
52
    /**
53
     * Set the Payload messages.
54
     *
55
     * @param  array  $output
0 ignored issues
show
There is no parameter named $output. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     *
57
     * @return $this
58
     */
59
    public function setMessages(array $messages)
60
    {
61
        return tap($this, function ($instance) use ($messages) {
62
            $instance->messages = [$instance->messagesWrapper => $messages];
63
        });
64
    }
65
66
    /**
67
     * Get messages array from the payload.
68
     *
69
     * @return array
70
     */
71
    public function getMessages()
72
    {
73
        return $this->messages;
74
    }
75
76
    /**
77
     * Set the Payload output.
78
     *
79
     * @param  mixed  $output
80
     * @param  string|null  $wrapper
81
     *
82
     * @return $this
83
     */
84
    public function setOutput($output, ? string $wrapper = null)
85
    {
86
        if ($wrapper) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $wrapper of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
87
            $this->setOutputWrapper($wrapper);
88
        }
89
90
        return tap($this, function ($instance) use ($output) {
91
            $instance->output = $output;
92
        });
93
    }
94
95
    /**
96
     * Get the Payload output.
97
     *
98
     * @return array
99
     */
100
    public function getOutput()
101
    {
102
        return $this->output;
103
    }
104
105
    /**
106
     * Get the unwrapped Payload output. Alias for getOutput.
107
     *
108
     * @return array
109
     */
110
    public function getUnwrappedOutput()
111
    {
112
        return $this->getOutput();
113
    }
114
115
    /**
116
     * Retrieve the Payload output and wrap it.
117
     * Use the outputWrapper if it is set. Otherwise use 'data'.
118
     *
119
     * @return array
120
     */
121
    public function getwrappedOutput()
122
    {
123
        return $this->outputWrapper ? [$this->outputWrapper => $this->output] : ['data' => $this->output];
124
    }
125
126
    /**
127
     * Set a wrapper for payload output.
128
     *
129
     * @param  string  $wrapper
130
     *
131
     * @return $this
132
     */
133
    private function setOutputWrapper(string $wrapper)
134
    {
135
        tap($this, function ($instance) use ($wrapper) {
0 ignored issues
show
The parameter $instance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
136
            $this->outputWrapper = $wrapper;
137
        });
138
    }
139
140
    /**
141
     * Get the wrapper for the output.
142
     *
143
     * @return string
144
     */
145
    public function getOutputWrapper()
146
    {
147
        return $this->outputWrapper;
148
    }
149
150
    /**
151
     * Get the wrapper for the messages.
152
     *
153
     * @return string
154
     */
155
    public function getMessagesWrapper()
156
    {
157
        return $this->messagesWrapper;
158
    }
159
160
    /**
161
     * Dynamically retrieve attributes on the OutputItem.
162
     *
163
     * @param  string  $key
164
     *
165
     * @return mixed
166
     */
167
    public function __get($key)
168
    {
169
        return $this->output[$key];
170
    }
171
172
    /**
173
     * Convert the Payload instance to JSON.
174
     *
175
     * @param  int  $options
176
     *
177
     * @return string
178
     */
179
    public function toJson($options = 0)
180
    {
181
        return json_encode($this->jsonSerialize(), $options);
182
    }
183
184
    /**
185
     * Convert the Payload into something JSON serializable.
186
     *
187
     * @return array
188
     */
189
    public function jsonSerialize()
190
    {
191
        return $this->toArray();
192
    }
193
194
    /**
195
     * Convert the Payload instance to an array.
196
     *
197
     * @return array
198
     */
199
    public function toArray()
200
    {
201
        $output = $this->outputWrapper || $this->messages ? $this->getwrappedOutput() : $this->output;
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->outputWrapper of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $this->messages of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
202
203
        return $this->messages ? array_merge($output, $this->messages) : $output;
204
    }
205
206
    /**
207
     * Determine if the given attribute exists.
208
     *
209
     * @param  mixed  $offset
210
     *
211
     * @return bool
212
     */
213
    public function offsetExists($offset)
214
    {
215
        return isset($this->$offset);
216
    }
217
218
    /**
219
     * Get the value for a given offset.
220
     *
221
     * @param  mixed  $offset
222
     *
223
     * @return mixed
224
     */
225
    public function offsetGet($offset)
226
    {
227
        return $this->$offset;
228
    }
229
230
    /**
231
     * Set the value for a given offset.
232
     *
233
     * @param  mixed  $offset
234
     * @param  mixed  $value
235
     */
236
    public function offsetSet($offset, $value)
237
    {
238
        $this->$offset = $value;
239
    }
240
241
    /**
242
     * Unset the value for a given offset.
243
     *
244
     * @param  mixed  $offset
245
     */
246
    public function offsetUnset($offset)
247
    {
248
        unset($this->$offset);
249
    }
250
251
    /**
252
     * Determine if an attribute exists on the Payload.
253
     *
254
     * @param  string  $key
255
     *
256
     * @return bool
257
     */
258
    public function __isset($key)
259
    {
260
        if (! $this->output) {
261
            return false;
262
        }
263
264
        return isset($this->output[$key]);
265
    }
266
267
    /**
268
     * Unset an attribute on the Payload.
269
     *
270
     * @param  string  $key
271
     */
272
    public function __unset($key)
273
    {
274
        if (! $this->output) {
275
            return;
276
        }
277
278
        unset($this->output[$key]);
279
    }
280
281
    /**
282
     * Convert the Payload to its string representation.
283
     *
284
     * @return string
285
     */
286
    public function __toString()
287
    {
288
        return $this->toJson();
289
    }
290
}
291