Issues (245)

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/Service/Action/Result.php (3 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
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Service\Action;
13
14
use Exception;
15
16
/**
17
 * Class Result
18
 *
19
 * @package CakeDC\Api\Service\Action
20
 */
21
class Result
22
{
23
24
    /**
25
     * Response code
26
     *
27
     * @var int
28
     */
29
    protected $_code = 200;
30
31
    /**
32
     * Response data
33
     *
34
     * @var array|mixed
35
     */
36
    protected $_data = null;
37
38
    /**
39
     * Response payload
40
     *
41
     * @var array
42
     */
43
    protected $_payload = [];
44
45
    /**
46
     * Exception structure
47
     *
48
     * @var Exception
49
     */
50
    protected $_exception = null;
51
52
    /**
53
     * Result constructor.
54
     *
55
     * @param array $data data to be delivered for the api
56
     * @param int $code code of the api request
57
     */
58 60
    public function __construct($data = null, $code = null)
59
    {
60 60
        if ($data !== null) {
61
            $this->setData($data);
62
        }
63 60
        if ($code !== null) {
64
            $this->setCode($code);
65
        }
66 60
    }
67
68
    /**
69
     * Gets a result data.
70
     *
71
     * @return array|mixed
72
     */
73 56
    public function getData()
74
    {
75 56
        return $this->_data;
76
    }
77
78
    /**
79
     * Sets a result data.
80
     *
81
     * @param array|mixed $value data to be delivered for the api
82
     * @return $this
83
     */
84 56
    public function setData($value)
85
    {
86 56
        $this->_data = $value;
87
88 56
        return $this;
89
    }
90
91
    /**
92
     * Get and set result data.
93
     *
94
     * @param array|mixed $value data to be delivered for the api
95
     * @deprecated 3.6.0 Use setData()/getData() instead.
96
     * @return array
97
     */
98
    public function data($value = null)
99
    {
100
        deprecationWarning(
101
            'Result::data() is deprecated. ' .
102
            'Use Result::setData()/getData() instead.'
103
        );
104
105
        if ($value !== null) {
106
            return $this->setData($value);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->setData($value); (CakeDC\Api\Service\Action\Result) is incompatible with the return type documented by CakeDC\Api\Service\Action\Result::data of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
107
        }
108
109
        return $this->getData();
110
    }
111
112
    /**
113
     * Gets a result code.
114
     *
115
     * @return int
116
     */
117 60
    public function getCode()
118
    {
119 60
        return $this->_code;
120
    }
121
122
    /**
123
     * Sets a result code.
124
     *
125
     * @param int $value code to be delivered for the api
126
     * @return $this
127
     */
128 59
    public function setCode($value)
129
    {
130 59
        $this->_code = $value;
131
132 59
        return $this;
133
    }
134
135
    /**
136
     * Code api method.
137
     *
138
     * @param int $value code of the api request
139
     * @deprecated 3.6.0 Use setCode()/getCode() instead.
140
     * @return int
141
     */
142
    public function code($value = null)
143
    {
144
        deprecationWarning(
145
            'Result::code() is deprecated. ' .
146
            'Use Result::setCode()/getCode() instead.'
147
        );
148
149
        if ($value !== null) {
150
            return $this->setCode($value);
151
        }
152
153
        return $this->getCode();
154
    }
155
156
    /**
157
     * Gets a result exception.
158
     *
159
     * @return Exception
160
     */
161 56
    public function getException()
162
    {
163 56
        return $this->_exception;
164
    }
165
166
    /**
167
     * Sets a result exception.
168
     *
169
     * @param Exception $value exception to be delivered for the api
170
     * @return $this
171
     */
172 8
    public function setException($value)
173
    {
174 8
        $this->_exception = $value;
175
176 8
        return $this;
177
    }
178
179
    /**
180
     * Exception api method.
181
     *
182
     * @param Exception $value exception of the api request
183
     * @deprecated 3.6.0 Use setException()/getException() instead.
184
     * @return Exception
185
     */
186
    public function exception($value = null)
187
    {
188
        deprecationWarning(
189
            'Result::exception() is deprecated. ' .
190
            'Use Result::setException()/getException() instead.'
191
        );
192
193
        if ($value !== null) {
194
            return $this->setException($value);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->setException($value); (CakeDC\Api\Service\Action\Result) is incompatible with the return type documented by CakeDC\Api\Service\Action\Result::exception of type Exception.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
195
        }
196
197
        return $this->getException();
198
    }
199
200
    /**
201
     * Appends value to Payload.
202
     *
203
     * @param string $key the key to be used in the payload
204
     * @param mixed $value value to be used as payload
205
     * @return void
206
     */
207 30
    public function appendPayload($key, $value)
208
    {
209 30
        $this->_payload[$key] = $value;
210 30
    }
211
212
    /**
213
     * Gets a result payload.
214
     *
215
     * @return array|mixed Payload
216
     */
217 54
    public function getPayload($key = null)
218
    {
219 54
        if ($key === null) {
220 54
            return $this->_payload;
221
        }
222
223
        if (isset($this->_payload[$key])) {
224
            return $this->_payload[$key];
225
        }
226
227
        return null;
228
    }
229
230
    /**
231
     * Sets a result payload.
232
     *
233
     * @param mixed $value payload to be delivered for the api
234
     * @return $this
235
     */
236
    public function setPayload($value)
237
    {
238
        $this->_payload = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type * is incompatible with the declared type array of property $_payload.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
239
240
        return $this;
241
    }
242
243
    /**
244
     * Payload api method.
245
     *
246
     * @param string $key payload of the api request
247
     * @deprecated 3.6.0 Use getPayload() instead.
248
     * @return mixed
249
     */
250
    public function payload($key = null)
251
    {
252
        deprecationWarning(
253
            'Result::payload() is deprecated. ' .
254
            'Use Result::getPayload() instead.'
255
        );
256
257
        return $this->getPayload($key);
258
    }
259
260
    /**
261
     * To array transformation.
262
     *
263
     * @return array
264
     */
265
    public function toArray()
266
    {
267
        $info = [
268
            'code' => $this->_code,
269
            'data' => $this->_data,
270
            'payload' => $this->_payload,
271
        ];
272
        if ($this->_exception !== null) {
273
            $info['exception'] = $this->_exception->getMessage();
274
            $info['exceptionStack'] = $this->_exception->getTraceAsString();
275
        }
276
277
        return $info;
278
    }
279
280
    /**
281
     * Returns an array that can be used to describe the internal state of this
282
     * object.
283
     *
284
     * @return array
285
     */
286
    public function __debugInfo()
287
    {
288
        return $this->toArray();
289
    }
290
}
291