Issues (20)

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/Api/Tweet.php (7 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
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Boilerplate\Api;
11
12
use FAPI\Boilerplate\Exception;
13
use FAPI\Boilerplate\Exception\Domain as DomainExceptions;
14
use FAPI\Boilerplate\Exception\InvalidArgumentException;
15
use FAPI\Boilerplate\Model\Tweet\TweetCreated;
16
use FAPI\Boilerplate\Model\Tweet\TweetDeleted;
17
use FAPI\Boilerplate\Model\Tweet\Tweets;
18
use FAPI\Boilerplate\Model\Tweet\Tweet as TweetModel;
19
use FAPI\Boilerplate\Model\Tweet\TweetUpdated;
20
use Psr\Http\Message\ResponseInterface;
21
22
/**
23
 * @author Tobias Nyholm <[email protected]>
24
 */
25
final class Tweet extends HttpApi
26
{
27
    /**
28
     * @param array $params
29
     *
30
     * @return Tweets|ResponseInterface
31
     *
32
     * @throws Exception
33
     */
34 View Code Duplication
    public function index(array $params = [])
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
        $response = $this->httpGet('/v1/tweets', $params);
37
38
        if (!$this->hydrator) {
39
            return $response;
40
        }
41
42
        // Use any valid status code here
43
        if ($response->getStatusCode() !== 200) {
44
            $this->handleErrors($response);
45
        }
46
47
        return $this->hydrator->hydrate($response, Tweets::class);
48
    }
49
50
    /**
51
     * @param int $id
52
     *
53
     * @return TweetModel|ResponseInterface
54
     *
55
     * @throws Exception
56
     */
57 View Code Duplication
    public function get(int $id)
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...
58
    {
59
        if (empty($id)) {
60
            throw new InvalidArgumentException('Id cannot be empty');
61
        }
62
63
        $response = $this->httpGet(sprintf('/v1/tweets/%d', $id));
64
65
        if (!$this->hydrator) {
66
            return $response;
67
        }
68
69
        // Use any valid status code here
70
        if ($response->getStatusCode() !== 200) {
71
            $this->handleErrors($response);
72
        }
73
74
        return $this->hydrator->hydrate($response, TweetModel::class);
75
    }
76
77
    /**
78
     * @param string $message
79
     * @param string $location
80
     * @param array  $hashtags
81
     *
82
     * @return TweetCreated|ResponseInterface
83
     *
84
     * @throws Exception
85
     */
86 View Code Duplication
    public function create(string $message, string $location, array $hashtags = [])
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...
87
    {
88
        if (empty($message)) {
89
            throw new InvalidArgumentException('Message cannot be empty');
90
        }
91
92
        if (empty($location)) {
93
            throw new InvalidArgumentException('Location cannot be empty');
94
        }
95
96
        $params = [
97
            'message' => $message,
98
            'location' => $location,
99
            'hashtags' => $hashtags,
100
        ];
101
102
        $response = $this->httpPost('/v1/tweets', $params);
103
104
        if (!$this->hydrator) {
105
            return $response;
106
        }
107
108
        // Use any valid status code here
109
        if ($response->getStatusCode() !== 201) {
110
            switch ($response->getStatusCode()) {
111
                case 400:
112
                    throw new DomainExceptions\ValidationException();
113
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
114
115
                default:
116
                    $this->handleErrors($response);
117
                    break;
118
            }
119
        }
120
121
        return $this->hydrator->hydrate($response, TweetCreated::class);
122
    }
123
124
    /**
125
     * @param int    $id
126
     * @param string $message
127
     * @param string $location
128
     * @param array  $hashtags
129
     *
130
     * @return TweetUpdated|ResponseInterface
131
     *
132
     * @throws Exception
133
     */
134 View Code Duplication
    public function update(int $id, string $message, string $location, array $hashtags = [])
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...
135
    {
136
        if (empty($message)) {
137
            throw new InvalidArgumentException('Message cannot be empty');
138
        }
139
140
        if (empty($location)) {
141
            throw new InvalidArgumentException('Location cannot be empty');
142
        }
143
144
        $params = [
145
            'message' => $message,
146
            'location' => $location,
147
            'hashtags' => $hashtags,
148
        ];
149
150
        $response = $this->httpPut(sprintf('/v1/tweets/%d', $id), $params);
151
152
        if (!$this->hydrator) {
153
            return $response;
154
        }
155
156
        // Use any valid status code here
157
        if ($response->getStatusCode() !== 200) {
158
            switch ($response->getStatusCode()) {
159
                case 400:
160
                    throw new DomainExceptions\ValidationException();
161
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
162
163
                default:
164
                    $this->handleErrors($response);
165
                    break;
166
            }
167
        }
168
169
        return $this->hydrator->hydrate($response, TweetUpdated::class);
170
    }
171
172
    /**
173
     * @param int $id
174
     *
175
     * @return TweetDeleted|ResponseInterface
176
     *
177
     * @throws Exception
178
     */
179 View Code Duplication
    public function delete(int $id)
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...
180
    {
181
        if (empty($id)) {
182
            throw new InvalidArgumentException('Id cannot be empty');
183
        }
184
185
        $response = $this->httpDelete(sprintf('/v1/tweets/%d', $id));
186
187
        if (!$this->hydrator) {
188
            return $response;
189
        }
190
191
        // Use any valid status code here
192
        if ($response->getStatusCode() !== 200) {
193
            $this->handleErrors($response);
194
        }
195
196
        return $this->hydrator->hydrate($response, TweetDeleted::class);
197
    }
198
}
199