Issues (5)

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/ApiResponse.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
namespace Tequilarapido\ApiResponse;
4
5
use Illuminate\Support\MessageBag;
6
7
class ApiResponse
8
{
9
    /**
10
     * @var FractalAdapter
11
     */
12
    private $fractalAdapter;
13
14
    /**
15
     * Response class.
16
     *
17
     * @param FractalAdapter $fractal
18
     */
19 13
    public function __construct(FractalAdapter $fractal)
20
    {
21 13
        $this->fractalAdapter = $fractal;
22 13
    }
23
24
    /**
25
     * Returns one item.
26
     *
27
     * @param mixed $data
28
     * @param null  $transformer
29
     * @param null  $resourceKey
30
     * @param bool  $build
31
     *
32
     * @return array|\Illuminate\Http\Response|ResponseBuilder
33
     */
34 2
    public function item($data, $transformer = null, $resourceKey = null, $build = true)
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...
35
    {
36 2
        return $this->toResponseBuilder(
37 2
            $this->fractalAdapter->item($data, $transformer, $resourceKey),
38 2
            $build
39
        );
40
    }
41
42
    /**
43
     * Returns collection.
44
     *
45
     * @param      $data
46
     * @param null $transformer
47
     * @param null $resourceKey
48
     * @param bool $build
49
     *
50
     * @return array|\Illuminate\Http\Response|ResponseBuilder
51
     */
52 2
    public function collection($data, $transformer = null, $resourceKey = null, $build = true)
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...
53
    {
54 2
        return $this->toResponseBuilder(
55 2
            $this->fractalAdapter->collection($data, $transformer, $resourceKey),
56 2
            $build
57
        );
58
    }
59
60
    /**
61
     * Returns paginated collection.
62
     *
63
     * @param      $paginator
64
     * @param null $transformer
65
     * @param null $resourceKey
66
     * @param bool $build
67
     *
68
     * @return array|\Illuminate\Http\Response|ResponseBuilder
69
     */
70 2
    public function paginatedCollection($paginator, $transformer = null, $resourceKey = null, $build = true)
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...
71
    {
72 2
        return $this->toResponseBuilder(
73 2
            $this->fractalAdapter->paginatedCollection($paginator, $transformer, $resourceKey),
74 2
            $build
75
        );
76
    }
77
78
    /**
79
     * Respond with a no content response.
80
     *
81
     * @param bool $build
82
     *
83
     * @return ResponseBuilder|\Illuminate\Http\Response
84
     */
85 1
    public function noContent($build = true)
86
    {
87 1
        $response = new ResponseBuilder(null);
88 1
        $response->setStatusCode(204);
89
90 1
        return $build ? $response->build() : $response;
91
    }
92
93
    /**
94
     * Return a 404 not found error.
95
     *
96
     * @param string|array $message
97
     * @param bool         $build
98
     *
99
     * @return \Illuminate\Http\Response
100
     */
101 1
    public function errorNotFound($message = 'Not Found', $build = true)
102
    {
103 1
        return $this->error($message, 404, null, $build);
104
    }
105
106
    /**
107
     * Return a 400 bad request error.
108
     *
109
     * @param string|array $message
110
     * @param bool         $build
111
     *
112
     * @return \Illuminate\Http\Response
113
     */
114 1
    public function errorBadRequest($message = 'Bad Request', $build = true)
115
    {
116 1
        return $this->error($message, 400, null, $build);
117
    }
118
119
    /**
120
     * Return a 401 unauthorized error.
121
     *
122
     * @param string|array $message
123
     * @param bool         $build
124
     *
125
     * @return \Illuminate\Http\Response
126
     */
127 1
    public function errorUnauthorized($message = 'Unauthorized', $build = true)
128
    {
129 1
        return $this->error($message, 401, null, $build);
130
    }
131
132
    /**
133
     * Return a 401 unauthorized error.
134
     *
135
     * @param string|array $message
136
     * @param bool         $build
137
     *
138
     * @return \Illuminate\Http\Response
139
     */
140 1
    public function errorForbidden($message = 'Forbidden', $build = true)
141
    {
142 1
        return $this->error($message, 403, null, $build);
143
    }
144
145
    /**
146
     * Return a 500 internal server error.
147
     *
148
     * @param string|array $message
149
     * @param bool         $build
150
     *
151
     * @return \Illuminate\Http\Response
152
     */
153 1
    public function errorInternal($message = 'Internal Error', $build = true)
154
    {
155 1
        return $this->error($message, 500, null, $build);
156
    }
157
158
    /**
159
     * Return an error response.
160
     *
161
     * @param                  $messages
162
     * @param int              $statusCode
163
     * @param mixed|MessageBag $errors
164
     * @param bool             $build
165
     *
166
     * @return \Illuminate\Http\Response
167
     */
168 6
    public function error($messages, $statusCode = 500, $errors = null, $build = true)
169
    {
170
        $error = [
171 6
            'error' => true,
172 6
            'code' => $statusCode,
173 6
            'message' => $messages,
174
        ];
175
176 6
        if (! is_null($errors)) {
177 1
            $error = array_merge($error, ['errors' => $errors]);
178
        }
179
180 6
        $response = (new ResponseBuilder($error))->setStatusCode($statusCode);
181
182 6
        return $build ? $response->build() : $response;
183
    }
184
185
    /**
186
     * Wrap into ResponseBuilder, and build if requested.
187
     * If not will return ResponseBuilder object, to be able to add headers for instance
188
     * before sending back response using `build()` method.
189
     *
190
     * @param $data
191
     * @param bool $build
192
     *
193
     * @return \Illuminate\Http\Response|ResponseBuilder
194
     */
195 6
    protected function toResponseBuilder($data, $build)
196
    {
197 6
        return $build
198 6
            ? (new ResponseBuilder($data))->build()
199 6
            : new ResponseBuilder($data);
200
    }
201
}
202