Issues (34)

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/Traits/ApiResponse.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
3
namespace Bytesfield\KeyManager\Traits;
4
5
use Bytesfield\KeyManager\Classes\Errors;
6
use Illuminate\Http\JsonResponse;
7
8
trait ApiResponse
9
{
10
    /**
11
     * Generates a not found response for a request.
12
     *
13
     * @param string $message
14
     * @return \Illuminate\Http\JsonResponse
15
     */
16
    public function notFound(string $message): JsonResponse
17
    {
18
        return $this->buildResponse($message, false, Errors::CODE['NOT_FOUND']);
19
    }
20
21
    /**
22
     * Generates a bad request response for a request.
23
     *
24
     * @param string $message
25
     * @return \Illuminate\Http\JsonResponse
26
     */
27
    public function badRequest(string $message): JsonResponse
28
    {
29
        return $this->buildResponse($message, false, Errors::CODE['BAD_REQUEST']);
30
    }
31
32
    /**
33
     * Generates a not found response for a request.
34
     *
35
     * @param string $message
36
     * @param array $errors
37
     * @return \Illuminate\Http\JsonResponse
38
     */
39
    public function failedValidation(string $message, array $errors = []): JsonResponse
40
    {
41
        return $this->buildResponse($message, false, Errors::CODE['VALIDATION_ERROR'], $errors);
42
    }
43
44
    /**
45
     * Generates an unauthorized response for a request.
46
     *
47
     * @param string $message.
0 ignored issues
show
There is no parameter named $message.. Did you maybe mean $message?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

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

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

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

Loading history...
48
     * @return \Illuminate\Http\JsonResponse
49
     */
50
    public function unauthorized(string $message): JsonResponse
51
    {
52
        return $this->buildResponse($message, false, Errors::CODE['UNAUTHORIZED']);
53
    }
54
55
    /**
56
     * Generates a method not found response for a request.
57
     *
58
     * @param string $message
59
     * @return \Illuminate\Http\JsonResponse
60
     */
61
    public function methodNotAllowed(string $message): JsonResponse
62
    {
63
        return $this->buildResponse($message, false, Errors::CODE['METHOD_NOT_FOUND']);
64
    }
65
66
    /**
67
     * Generates a failed Data Creation response for a request.
68
     *
69
     * @param string $message
70
     * @return \Illuminate\Http\JsonResponse
71
     */
72
    public function failedDataCreation(string $message): JsonResponse
73
    {
74
        return $this->buildResponse($message, false, Errors::CODE['BAD_REQUEST']);
75
    }
76
77
    /**
78
     * Generates a success response for a request.
79
     *
80
     * @param string $message
81
     * @param array $data
82
     * @return \Illuminate\Http\JsonResponse
83
     */
84
    public function success(string $message, array $data = []): JsonResponse
85
    {
86
        return $this->buildResponse($message, true, Errors::CODE['OK'], $data);
87
    }
88
89
    /**
90
     * Generates a success response for a request.
91
     *
92
     * @param string $message
93
     * @param array $data
94
     * @return \Illuminate\Http\JsonResponse
95
     */
96
    public function actionSuccess(string $message, array $data = []): JsonResponse
97
    {
98
        return $this->buildResponse($message, true, Errors::CODE['OK'], $data);
99
    }
100
101
    /**
102
     * Generates an error response for a request.
103
     *
104
     * @param string $message
105
     * @return \Illuminate\Http\JsonResponse
106
     */
107
    public function error(string $message): JsonResponse
108
    {
109
        return $this->buildResponse($message, false, Errors::CODE['CONFLICT']);
110
    }
111
112
    /**
113
     * Generates a server error response for a request.
114
     *
115
     * @param string $message
116
     * @return \Illuminate\Http\JsonResponse
117
     */
118
    public function serverError(string $message): JsonResponse
119
    {
120
        return $this->buildResponse($message, false, Errors::CODE['SERVER_ERROR']);
121
    }
122
123
    /**
124
     * Generates a forbidden response for a request.
125
     *
126
     * @param string $message
127
     *
128
     * @return \Illuminate\Http\JsonResponse
129
     */
130
    public function forbidden(string $message): JsonResponse
131
    {
132
        return $this->buildResponse($message, false, Errors::CODE['FORBIDDEN']);
133
    }
134
135
    /**
136
     * Built a response for a request.
137
     *
138
     * @param string $message
139
     * @param bool $status
140
     * @param int $statusCode
141
     * @param array $data
142
     * @param array $headers
143
     * @return \Illuminate\Http\JsonResponse
144
     */
145
    private function buildResponse(
146
        string $message,
147
        bool $status,
148
        int $statusCode,
149
        array $data = [],
150
        array $headers = []
0 ignored issues
show
The parameter $headers 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...
151
    ) {
152
        $responseData = [
153
            'status' => $status,
154
            'statusCode' => $statusCode,
155
            'message' => $message,
156
        ];
157
158
        if (! empty($data)) {
159
            $responseData['data'] = $data;
160
        }
161
162
        return new JsonResponse($responseData, $statusCode);
163
    }
164
}
165