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/Services/HelpDocs.php (1 issue)

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 DigitalEquation\Teamwork\Services;
4
5
use DigitalEquation\Teamwork\Exceptions\TeamworkHttpException;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\ClientException;
8
use GuzzleHttp\Pool as GuzzlePool;
9
use GuzzleHttp\Psr7\Request as GuzzleRequest;
10
use GuzzleHttp\Psr7\Response;
11
use GuzzleHttp\Psr7\Stream;
12
13
class HelpDocs
14
{
15
    /**
16
     * @var \GuzzleHttp\Client
17
     */
18
    private Client $client;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
19
20
    /**
21
     * HelpDocs constructor.
22
     *
23
     * @param \GuzzleHttp\Client $client
24
     */
25
    public function __construct(Client $client)
26
    {
27
        $this->client = $client;
28
    }
29
30
    /**
31
     * Get HelpDocs sites.
32
     *
33
     * @return array
34
     * @throws \DigitalEquation\Teamwork\Exceptions\TeamworkHttpException
35
     * @throws \GuzzleHttp\Exception\GuzzleException
36
     * @throws \JsonException
37
     */
38
    public function getSites(): array
39
    {
40
        try {
41
            /** @var Response $response */
42
            $response = $this->client->get('helpdocs/sites.json');
43
            /** @var Stream $body */
44
            $body = $response->getBody();
45
46
            return json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
47
        } catch (ClientException $e) {
48
            throw new TeamworkHttpException($e->getMessage(), 400);
49
        }
50
    }
51
52
    /**
53
     * Get HelpDocs site.
54
     *
55
     * @param int $siteID
56
     *
57
     * @return array
58
     * @throws \DigitalEquation\Teamwork\Exceptions\TeamworkHttpException
59
     * @throws \GuzzleHttp\Exception\GuzzleException
60
     * @throws \JsonException
61
     */
62
    public function getSite(int $siteID): array
63
    {
64
        try {
65
            /** @var Response $response */
66
            $response = $this->client->get(sprintf('helpdocs/sites/%s.json', $siteID));
67
            /** @var Stream $body */
68
            $body = $response->getBody();
69
70
            return json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
71
        } catch (ClientException $e) {
72
            throw new TeamworkHttpException($e->getMessage(), 400);
73
        }
74
    }
75
76
    /**
77
     * Get articles within a category.
78
     *
79
     * @param int $categoryID
80
     * @param int $page
81
     *
82
     * @return array
83
     * @throws \DigitalEquation\Teamwork\Exceptions\TeamworkHttpException
84
     * @throws \GuzzleHttp\Exception\GuzzleException
85
     * @throws \JsonException
86
     */
87
    public function getCategoryArticles($categoryID, $page = 1): array
88
    {
89
        try {
90
            /** @var Response $response */
91
            $response = $this->client->get(sprintf('helpdocs/categories/%s/articles.json', $categoryID), [
92
                'query' => compact('page'),
93
            ]);
94
            /** @var Stream $body */
95
            $body = $response->getBody();
96
97
            return json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
98
        } catch (ClientException $e) {
99
            throw new TeamworkHttpException($e->getMessage(), 400);
100
        }
101
    }
102
103
    /**
104
     * Get articles within a site.
105
     *
106
     * @param int $siteID
107
     * @param int $page
108
     *
109
     * @return array
110
     * @throws \DigitalEquation\Teamwork\Exceptions\TeamworkHttpException
111
     * @throws \GuzzleHttp\Exception\GuzzleException
112
     * @throws \JsonException
113
     */
114
    public function getSiteArticles(int $siteID, $page = 1): array
115
    {
116
        try {
117
            /** @var Response $response */
118
            $response = $this->client->get(sprintf('helpdocs/sites/%s/articles.json', $siteID), [
119
                'query' => compact('page'),
120
            ]);
121
            /** @var Stream $body */
122
            $body = $response->getBody();
123
124
            return json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
125
        } catch (ClientException $e) {
126
            throw new TeamworkHttpException($e->getMessage(), 400);
127
        }
128
    }
129
130
    /**
131
     * Get article by id.
132
     *
133
     * @param int $articleID
134
     *
135
     * @return array
136
     * @throws \DigitalEquation\Teamwork\Exceptions\TeamworkHttpException
137
     * @throws \GuzzleHttp\Exception\GuzzleException
138
     * @throws \JsonException
139
     */
140
    public function getArticle(int $articleID): array
141
    {
142
        try {
143
            /** @var Response $response */
144
            $response = $this->client->get(sprintf('helpdocs/articles/%s.json', $articleID));
145
            /** @var Stream $body */
146
            $body = $response->getBody();
147
148
            return json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
149
        } catch (ClientException $e) {
150
            throw new TeamworkHttpException($e->getMessage(), 400);
151
        }
152
    }
153
154
    /**
155
     * Get articles (in bulk).
156
     *
157
     * @param int[] $articleIDs
158
     *
159
     * @return array
160
     */
161
    public function getArticles(array $articleIDs): array
162
    {
163
        $articles = [];
164
165
        $requests = array_map(static function ($articleID) {
166
            return new GuzzleRequest('GET', sprintf('helpdocs/articles/%s.json', $articleID));
167
        }, $articleIDs);
168
169
        $pool = new GuzzlePool($this->client, $requests, [
170
            'concurrency' => 10,
171
            'fulfilled'   => function ($response) use (&$articles) {
172
                $response = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
173
174
                $articles[] = $response['article'];
175
            },
176
        ]);
177
178
        $promise = $pool->promise();
179
        $promise->wait();
180
181
        return $articles;
182
    }
183
184
    /**
185
     * Get categories within a site.
186
     *
187
     * @param int $siteID
188
     *
189
     * @return array
190
     * @throws \DigitalEquation\Teamwork\Exceptions\TeamworkHttpException
191
     * @throws \GuzzleHttp\Exception\GuzzleException
192
     * @throws \JsonException
193
     */
194
    public function getSiteCategories(int $siteID): array
195
    {
196
        try {
197
            /** @var Response $response */
198
            $response = $this->client->get(sprintf('helpdocs/sites/%s/categories.json', $siteID));
199
            /** @var Stream $body */
200
            $body = $response->getBody();
201
202
            return json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
203
        } catch (ClientException $e) {
204
            throw new TeamworkHttpException($e->getMessage(), 400);
205
        }
206
    }
207
}
208