Issues (318)

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/Files.php (15 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 SevenShores\Hubspot\Resources;
4
5
class Files extends Resource
6
{
7
    /**
8
     * Upload a new file.
9
     *
10
     * @param string $file   File path
11
     * @param array  $params Optional parameters
12
     * @return \SevenShores\Hubspot\Http\Response
13
     */
14
    function upload($file, $params = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
    {
16
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files";
17
18
        $queryString = build_query_string([
19
            'overwrite' => isset($params['overwrite']) ? $params['overwrite'] : false,
20
        ]);
21
22
        $options['multipart'] = [
23
            [
24
                'name' => 'files',
25
                'contents' => fopen($file, 'rb')
26
            ],
27
            [
28
                'name' => 'file_names',
29
                'contents' => isset($params['file_names']) ? $params['file_names'] : null
30
            ],[
31
                'name' => 'folder_paths',
32
                'contents' => isset($params['folder_paths']) ? $params['folder_paths'] : null
33
            ]
34
        ];
35
36
        return $this->client->request('post', $endpoint, $options, $queryString);
37
    }
38
39
    /**
40
     * Get meta data for all files.
41
     *
42
     * @param array $params Optional parameters
43
     * @return \SevenShores\Hubspot\Http\Response
44
     */
45
    function all($params = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
    {
47
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files";
48
49
        $queryString = build_query_string($params);
50
51
        return $this->client->request('get', $endpoint, [], $queryString);
52
    }
53
54
55
    /**
56
     * Upload a replacement file.
57
     *
58
     * @param int    $file_id The file ID
59
     * @param string $file    The file path
60
     * @return \SevenShores\Hubspot\Http\Response
61
     */
62
    function replace($file_id, $file)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
    {
64
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files/{$file_id}";
65
66
        $options['multipart'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
67
            [
68
                'name' => 'files',
69
                'contents' => fopen($file, 'rb')
70
            ]
71
        ];
72
73
        return $this->client->request('post', $endpoint, $options);
74
    }
75
76
    /**
77
     * Get file metadata.
78
     *
79
     * @param $file_id
80
     * @return \SevenShores\Hubspot\Http\Response
81
     */
82
    function meta($file_id)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
    {
84
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files/{$file_id}";
85
86
        return $this->client->request('get', $endpoint);
87
    }
88
89
    /**
90
     * Archive a file.
91
     *
92
     * @param int $file_id The file ID
93
     * @return \SevenShores\Hubspot\Http\Response
94
     */
95
    function archive($file_id)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
96
    {
97
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files/{$file_id}/archive";
98
99
        return $this->client->request('post', $endpoint);
100
    }
101
102
    /**
103
     * Delete a file.
104
     *
105
     * @param int $file_id The file ID
106
     * @return \SevenShores\Hubspot\Http\Response
107
     */
108
    function delete($file_id)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
109
    {
110
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files/{$file_id}";
111
112
        return $this->client->request('delete', $endpoint);
113
    }
114
115
    /**
116
     * Move a file to a new folder.
117
     *
118
     * Parameters:
119
     * folder_path  string    The path of the folder to move the file into. Use this OR folder_id - not both.
120
     * folder_id    string    The id of the folder to move the file into. Use this OR folder_path - not both.
121
     * name            string    The new name of the file.
122
     *
123
     * @param int   $file_id
124
     * @param array $params
125
     * @return \SevenShores\Hubspot\Http\Response
126
     */
127
    function move($file_id, $params = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
128
    {
129
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/files/{$file_id}/move-file";
130
131
        $options['json'] = $params;
132
133
        return $this->client->request('post', $endpoint, $options);
134
    }
135
136
    /**
137
     * Create a new folder.
138
     *
139
     * @param string $folder_name
140
     * @param int    $parent_folder_id
141
     * @return \SevenShores\Hubspot\Http\Response
142
     */
143 View Code Duplication
    function createFolder($folder_name, $parent_folder_id)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
144
    {
145
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/folders";
146
147
        $options['json'] = [
148
            'name'             => $folder_name,
149
            'parent_folder_id' => $parent_folder_id,
150
        ];
151
152
        return $this->client->request('post', $endpoint, $options);
153
    }
154
155
    /**
156
     * List folders metadata.
157
     *
158
     * @param array $params
159
     * @return \SevenShores\Hubspot\Http\Response
160
     */
161
    function folders($params = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
162
    {
163
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/folders";
164
165
        $queryString = build_query_string($params);
166
167
        return $this->client->request('get', $endpoint, [], $queryString);
168
    }
169
170
    /**
171
     * Update a folder.
172
     *
173
     * @param int   $folder_id
174
     * @param array $params
175
     * @return \SevenShores\Hubspot\Http\Response
176
     */
177
    function updateFolder($folder_id, $params = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
178
    {
179
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/folders/{$folder_id}";
180
181
        $options['json'] = $params;
182
183
        return $this->client->request('put', $endpoint, $options);
184
    }
185
186
    /**
187
     * Delete a folder.
188
     *
189
     * @param int $folder_id
190
     * @return \SevenShores\Hubspot\Http\Response
191
     */
192
    function deleteFolder($folder_id)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
193
    {
194
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/folders/{$folder_id}";
195
196
        return $this->client->request('delete', $endpoint);
197
    }
198
199
    /**
200
     * Get the folder by ID.
201
     *
202
     * @param int $folder_id
203
     * @return \SevenShores\Hubspot\Http\Response
204
     */
205
    function getFolderById($folder_id)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
206
    {
207
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/folders/{$folder_id}";
208
209
        return $this->client->request('get', $endpoint);
210
    }
211
212
    /**
213
     * Move a folder.
214
     *
215
     * @param int   $folder_id
216
     * @param array $params
217
     * @return \SevenShores\Hubspot\Http\Response
218
     */
219
    function moveFolder($folder_id, $params = [])
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
220
    {
221
        $endpoint = "https://api.hubapi.com/filemanager/api/v2/folders/{$folder_id}/move-folder";
222
223
        $options['json'] = $params;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
224
225
        return $this->client->request('post', $endpoint, $options);
226
    }
227
228
}
229