Issues (9)

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/Resources/Messages.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
 * This file is part of GitterApi package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace Gitter\Resources;
10
11
use Gitter\Route;
12
13
/**
14
 * Messages represent individual chat messages sent to a room. They are a sub-resource of a room.
15
 * Message schema:
16
 *  - id:           ID of the message.
17
 *  - text:         Original message in plain-text/markdown.
18
 *  - html:         HTML formatted message.
19
 *  - sent:         ISO formatted date of the message.
20
 *  - editedAt:     ISO formatted date of the message if edited.
21
 *  - fromUser:     (User)[user-resource] that sent the message.
22
 *  - unread:       Boolean that indicates if the current user has read the message.
23
 *  - readBy:       Number of users that have read the message.
24
 *  - urls:         List of URLs present in the message.
25
 *  - mentions:     List of @Mentions in the message.
26
 *  - issues:       List of #Issues referenced in the message.
27
 *  - meta:         Metadata. This is currently not used for anything.
28
 *  - v:            Version.
29
 *  - gv:           Stands for "Gravatar version" and is used for cache busting.
30
 * @package Gitter\Resources
31
 */
32
class Messages extends AbstractResource
33
{
34
    /**
35
     * List of messages in a room in historical reversed order.
36
     *
37
     * @param string $roomId Room id
38
     * @param string|null $query Optional search query
39
     * @return \Generator
40
     * @throws \InvalidArgumentException
41
     * @throws \Throwable
42
     * @throws \Exception
43
     */
44
    public function all(string $roomId, string $query = null): \Generator
45
    {
46
        yield from $this->allBeforeId($roomId, null, $query);
47
    }
48
49
    /**
50
     * Returns all messages before target message id.
51
     *
52
     * @param string $roomId
53
     * @param string|null $beforeId
54
     * @param string|null $query
55
     * @return \Generator
56
     * @throws \Exception
57
     * @throws \InvalidArgumentException
58
     * @throws \Throwable
59
     */
60 View Code Duplication
    public function allBeforeId(string $roomId, string $beforeId = null, string $query = null)
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...
61
    {
62
        $limit = 100;
63
        $route = $this->routeForMessagesIterator($roomId, $limit, $query);
64
65
        do {
66
            if ($beforeId !== null) {
67
                $route->with('beforeId', $beforeId);
68
            }
69
70
            $response = \array_reverse($this->fetch($route));
71
72
            foreach ($response as $message) {
73
                yield $message;
74
            }
75
76
            $beforeId = \count($response) > 0 ? \end($response)['id'] : null;
77
        } while (\count($response) >= $limit);
78
    }
79
80
    /**
81
     * @param string $roomId
82
     * @param int $limit
83
     * @param string|null $query
84
     * @return Route
85
     */
86
    private function routeForMessagesIterator(string $roomId, int $limit, string $query = null): Route
87
    {
88
        $route = Route::get('rooms/{roomId}/chatMessages')
89
            ->with('roomId', $roomId)
90
            ->with('limit', (string)$limit);
91
92
        if ($query !== null) {
93
            $route->with('q', $query);
94
        }
95
96
        return $route;
97
    }
98
99
    /**
100
     * Returns all messages after target message id.
101
     *
102
     * @param string $roomId
103
     * @param string|null $afterId
104
     * @param string|null $query
105
     * @return \Generator
106
     * @throws \Exception
107
     * @throws \InvalidArgumentException
108
     * @throws \Throwable
109
     */
110 View Code Duplication
    public function allAfterId(string $roomId, string $afterId = null, string $query = null)
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...
111
    {
112
        $limit = 100;
113
        $route = $this->routeForMessagesIterator($roomId, $limit, $query);
114
115
        do {
116
            if ($afterId !== null) {
117
                $route->with('afterId', $afterId);
118
            }
119
120
            $response = (array)$this->fetch($route);
121
122
            foreach ($response as $message) {
123
                yield $message;
124
            }
125
126
            $afterId = \count($response) > 0 ? end($response)['id'] : null;
127
        } while (\count($response) >= $limit);
128
    }
129
130
    /**
131
     * There is also a way to retrieve a single message using its id.
132
     *
133
     * @param string $roomId Room id
134
     * @param string $messageId Message id
135
     * @return array
136
     * @throws \InvalidArgumentException
137
     * @throws \Throwable
138
     * @throws \Exception
139
     */
140
    public function find(string $roomId, string $messageId): array
141
    {
142
        return $this->fetch(
143
            Route::get('rooms/{roomId}/chatMessages/{messageId}')
144
                ->withMany(['roomId' => $roomId, 'messageId' => $messageId])
145
        );
146
    }
147
148
    /**
149
     * Send a message to a room.
150
     *
151
     * @param string $roomId Room id
152
     * @param string $content Message body
153
     * @return array
154
     * @throws \InvalidArgumentException
155
     * @throws \Throwable
156
     * @throws \Exception
157
     */
158
    public function create(string $roomId, string $content): array
159
    {
160
        return $this->fetch(
161
            Route::post('rooms/{roomId}/chatMessages')
162
                ->with('roomId', $roomId)
163
                ->withBody('text', $content)
164
        );
165
    }
166
167
    /**
168
     * Delete a message.
169
     *
170
     * @param string $roomId
171
     * @param string $messageId
172
     * @return array
173
     * @throws \RuntimeException
174
     * @throws \InvalidArgumentException
175
     * @throws \Throwable
176
     * @throws \Exception
177
     * @throws \GuzzleHttp\Exception\ClientException
178
     */
179
    public function delete(string $roomId, string $messageId): array
180
    {
181
        return $this->update($roomId, $messageId, '');
182
    }
183
184
    /**
185
     * Update a message.
186
     *
187
     * @param string $roomId Room id
188
     * @param string $messageId Message id
189
     * @param string $content New message body
190
     * @return array
191
     * @throws \InvalidArgumentException
192
     * @throws \Throwable
193
     * @throws \Exception
194
     */
195
    public function update(string $roomId, string $messageId, string $content): array
196
    {
197
        return $this->fetch(
198
            Route::put('rooms/{roomId}/chatMessages/{messageId}')
199
                ->withMany(['roomId' => $roomId, 'messageId' => $messageId])
200
                ->withBody('text', $content)
201
        );
202
    }
203
}
204