Completed
Push — d64 ( c69f98...4484ee )
by Welling
03:12 queued 01:04
created

ClientRemote::getActivity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 3
Ratio 25 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 3
loc 12
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Directus – <http://getdirectus.com>
5
 *
6
 * @link      The canonical repository – <https://github.com/directus/directus>
7
 * @copyright Copyright 2006-2016 RANGER Studio, LLC – <http://rangerstudio.com>
8
 * @license   GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html>
9
 */
10
11
namespace Directus\SDK;
12
use Directus\Util\ArrayUtils;
13
use Directus\Util\DateUtils;
14
use Directus\Util\StringUtils;
15
16
/**
17
 * Client Remote
18
 *
19
 * @author Welling Guzmán <[email protected]>
20
 */
21
class ClientRemote extends BaseClientRemote
22
{
23
    /**
24
     * @inheritdoc
25
     */
26 2
    public function getTables(array $params = [])
27
    {
28 2
        return $this->performRequest('GET', static::TABLE_LIST_ENDPOINT);
1 ignored issue
show
Bug Compatibility introduced by
The expression $this->performRequest('G...::TABLE_LIST_ENDPOINT); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 28 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTables of type Directus\SDK\Response\EntryCollection.
Loading history...
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 4
    public function getTable($tableName)
35
    {
36 4
        $path = $this->buildPath(static::TABLE_INFORMATION_ENDPOINT, $tableName);
37
38 4
        return $this->performRequest('GET', $path);
1 ignored issue
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 38 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTable of type Directus\SDK\Response\Entry.
Loading history...
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 2
    public function getColumns($tableName, array $params = [])
45
    {
46 2
        $path = $this->buildPath(static::COLUMN_LIST_ENDPOINT, $tableName);
47
48 2
        return $this->performRequest('GET', $path);
1 ignored issue
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 48 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumns of type Directus\SDK\Response\EntryCollection.
Loading history...
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 2
    public function getColumn($tableName, $columnName)
55
    {
56 2
        $path = $this->buildPath(static::COLUMN_INFORMATION_ENDPOINT, [$tableName, $columnName]);
57
58 2
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 58 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumn of type Directus\SDK\Response\Entry.
Loading history...
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64 2
    public function getItems($tableName, array $options = [])
65
    {
66 2
        $path = $this->buildPath(static::TABLE_ENTRIES_ENDPOINT, $tableName);
0 ignored issues
show
Documentation introduced by
$tableName is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
68 2
        return $this->performRequest('GET', $path, ['query' => $options]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('G...('query' => $options)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 68 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItems of type Directus\SDK\Response\EntryCollection.
Loading history...
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74 2
    public function getItem($tableName, $id, array $options = [])
75
    {
76 2
        $path = $this->buildPath(static::TABLE_ENTRY_ENDPOINT, [$tableName, $id]);
77
78 2
        return $this->performRequest('GET', $path, ['query' => $options]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('G...('query' => $options)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 78 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItem of type Directus\SDK\Response\Entry.
Loading history...
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 2
    public function getUsers(array $params = [])
85
    {
86 2
        return $this->getItems('directus_users', $params);
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92 2
    public function getUser($id, array $params = [])
93
    {
94 2
        return $this->getItem($id, 'directus_users', $params);
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100 2
    public function getGroups()
101
    {
102 2
        return $this->performRequest('GET', static::GROUP_LIST_ENDPOINT);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('G...::GROUP_LIST_ENDPOINT); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 102 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroups of type Directus\SDK\Response\EntryCollection.
Loading history...
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 2
    public function getGroup($groupID)
109
    {
110 2
        $path = $this->buildPath(static::GROUP_INFORMATION_ENDPOINT, $groupID);
111
112 2
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 112 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroup of type Directus\SDK\Response\Entry.
Loading history...
113
    }
114
115
    /**
116
     * @inheritdoc
117
     */
118 2
    public function getGroupPrivileges($groupID)
119
    {
120 2
        $path = $this->buildPath(static::GROUP_PRIVILEGES_ENDPOINT, $groupID);
121
122 2
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 122 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroupPrivileges of type Directus\SDK\Response\EntryCollection.
Loading history...
123
    }
124
125
    /**
126
     * @inheritdoc
127
     */
128 2
    public function getFiles()
129
    {
130 2
        return $this->performRequest('GET', static::FILE_LIST_ENDPOINT);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('G...c::FILE_LIST_ENDPOINT); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 130 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getFiles of type Directus\SDK\Response\EntryCollection.
Loading history...
131
    }
132
133
    /**
134
     * @inheritdoc
135
     */
136 2
    public function getFile($fileID)
137
    {
138 2
        $path = $this->buildPath(static::FILE_INFORMATION_ENDPOINT, $fileID);
139
140 2
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 140 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getFile of type Directus\SDK\Response\Entry.
Loading history...
141
    }
142
143
    /**
144
     * @inheritdoc
145
     */
146 2
    public function getSettings()
147
    {
148 2
        return $this->performRequest('GET', static::SETTING_LIST_ENDPOINT);
149
    }
150
151
    /**
152
     * @inheritdoc
153
     */
154 2
    public function getSettingsByCollection($collectionName)
155
    {
156 2
        $path = $this->buildPath(static::SETTING_COLLECTION_ENDPOINT, $collectionName);
157
158 2
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 158 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...getSettingsByCollection of type Directus\SDK\Response\EntryCollection.
Loading history...
159
    }
160
161
    /**
162
     * @inheritdoc
163
     */
164
    public function getMessages($userId)
165
    {
166
        $path = $this->buildPath(static::MESSAGES_USER_ENDPOINT, $userId);
167
168
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 168 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getMessages of type Directus\SDK\Response\EntryCollection.
Loading history...
169
    }
170
171
    /**
172
     * @inheritdoc
173
     */
174 View Code Duplication
    public function createItem($tableName, array $data)
0 ignored issues
show
Duplication introduced by
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...
175
    {
176
        $path = $this->buildPath(static::TABLE_ENTRY_CREATE_ENDPOINT, $tableName);
177
        $data = $this->processData($tableName, $data);
178
179
        return $this->performRequest('POST', $path, ['body' => $data]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 179 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createItem of type Directus\SDK\Response\Entry.
Loading history...
180
    }
181
182
    /**
183
     * @inheritdoc
184
     */
185 View Code Duplication
    public function updateItem($tableName, $id, array $data)
0 ignored issues
show
Duplication introduced by
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...
186
    {
187
        $path = $this->buildPath(static::TABLE_ENTRY_UPDATE_ENDPOINT, [$tableName, $id]);
188
        $data = $this->processData($tableName, $data);
189
190
        return $this->performRequest('PUT', $path, ['body' => $data]);
191
    }
192
193
    /**
194
     * @inheritdoc
195
     */
196
    public function deleteItem($tableName, $id)
197
    {
198
        $path = $this->buildPath(static::TABLE_ENTRY_DELETE_ENDPOINT, [$tableName, $id]);
199
200
        return $this->performRequest('DELETE', $path);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->performRequest('DELETE', $path); (Directus\SDK\Response\En...ctus\SDK\Response\Entry) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteItem of type integer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
201
    }
202
203
    /**
204
     * @inheritdoc
205
     */
206
    public function createUser(array $data)
207
    {
208
        return $this->createItem('directus_users', $data);
209
    }
210
211
    /**
212
     * @inheritdoc
213
     */
214
    public function updateUser($id, array $data)
215
    {
216
        return $this->updateItem('directus_users', $id, $data);
217
    }
218
219
    /**
220
     * @inheritdoc
221
     */
222
    public function deleteUser($ids)
223
    {
224
        return $this->deleteItem('directus_users', $ids);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deleteItem('directus_users', $ids); (Directus\SDK\Response\En...ctus\SDK\Response\Entry) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteUser of type integer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
225
    }
226
227
    /**
228
     * @inheritdoc
229
     */
230
    public function createFile(File $file)
231
    {
232
        $data = $this->processFile($file);
233
234
        return $this->performRequest('POST', static::FILE_CREATE_ENDPOINT, ['body' => $data]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 234 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createFile of type Directus\SDK\Response\Entry.
Loading history...
235
    }
236
237
    /**
238
     * @inheritdoc
239
     */
240
    public function updateFile($id, $data)
241
    {
242
        if ($data instanceof File) {
243
            $data = $data->toArray();
244
        }
245
246
        $data['id'] = $id;
247
        $path = $this->buildPath(static::FILE_UPDATE_ENDPOINT, $id);
248
        $data = $this->processData('directus_files', $data);
249
250
        return $this->performRequest('POST', $path, ['body' => $data]);
251
    }
252
253
    /**
254
     * @inheritdoc
255
     */
256
    public function deleteFile($id)
257
    {
258
        return $this->deleteItem('directus_files', $id);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deleteItem('directus_files', $id); (Directus\SDK\Response\En...ctus\SDK\Response\Entry) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteFile of type integer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
259
    }
260
261
    public function createPreferences($data)
262
    {
263
        $this->requiredAttributes(['title', 'table_name'], $data);
264
265
        $tableName = ArrayUtils::get($data, 'table_name');
266
        $path = $this->buildPath(static::TABLE_PREFERENCES_ENDPOINT, $tableName);
267
        $data = $this->processData($tableName, $data);
268
269
        return $this->performRequest('POST', $path, ['body' => $data]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 269 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPreferences of type Directus\SDK\Response\Entry.
Loading history...
270
    }
271
272
    /**
273
     * @inheritdoc
274
     */
275
    public function createBookmark($data)
276
    {
277
        $preferences = $this->createPreferences(ArrayUtils::pick($data, [
278
            'title', 'table_name', 'sort', 'status', 'search_string', 'sort_order', 'columns_visible'
279
        ]));
280
281
        $title = $preferences->title;
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Directus\SDK\Response\Entry>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
282
        $tableName = $preferences->table_name;
0 ignored issues
show
Documentation introduced by
The property table_name does not exist on object<Directus\SDK\Response\Entry>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
283
        $bookmarkData = [
284
            'section' => 'search',
285
            'title' => $title,
286
            'url' => 'tables/' . $tableName . '/pref/' . $title
287
        ];
288
289
        $path = $this->buildPath(static::BOOKMARKS_CREATE_ENDPOINT);
290
        $bookmarkData = $this->processData($tableName, $bookmarkData);
291
292
        return $this->performRequest('POST', $path, ['body' => $bookmarkData]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...dy' => $bookmarkData)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 292 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createBookmark of type Directus\SDK\Response\Entry.
Loading history...
293
    }
294
295
    /**
296
     * @inheritdoc
297
     */
298
    public function getBookmark($id)
299
    {
300
        $path = $this->buildPath(static::BOOKMARKS_READ_ENDPOINT, $id);
0 ignored issues
show
Documentation introduced by
$id is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
301
302
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 302 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getBookmark of type Directus\SDK\Response\Entry.
Loading history...
303
    }
304
305
    /**
306
     * @inheritdoc
307
     */
308
    public function getBookmarks($userId = null)
309
    {
310
        if ($userId !== null) {
311
            $path = $this->buildPath(static::BOOKMARKS_USER_ENDPOINT, $userId);
0 ignored issues
show
Documentation introduced by
$userId is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
312
        } else {
313
            $path = $this->buildPath(static::BOOKMARKS_ALL_ENDPOINT);
314
        }
315
316
        return $this->performRequest('GET', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('GET', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 316 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getBookmarks of type Directus\SDK\Response\Entry.
Loading history...
317
    }
318
319
    /**
320
     * @inheritdoc
321
     */
322
    public function createColumn($data)
323
    {
324
        $data = $this->parseColumnData($data);
325
326
        return $this->performRequest('POST', $this->buildPath(static::COLUMN_CREATE_ENDPOINT, $data['table_name']), [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 326 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createColumn of type Directus\SDK\Response\Entry.
Loading history...
327
            'body' => $data
328
        ]);
329
    }
330
331
    /**
332
     * @inheritdoc
333
     */
334
    public function createGroup(array $data)
335
    {
336
        return $this->performRequest('POST', static::GROUP_CREATE_ENDPOINT, [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 336 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createGroup of type Directus\SDK\Response\Entry.
Loading history...
337
            'body' => $data
338
        ]);
339
    }
340
341
    /**
342
     * @inheritdoc
343
     */
344
    public function createMessage(array $data)
345
    {
346
        $this->requiredAttributes(['from', 'message', 'subject'], $data);
347
        $this->requiredOneAttribute(['to', 'toGroup'], $data);
348
349
        $data['recipients'] = $this->getMessagesTo($data);
350
        ArrayUtils::remove($data, ['to', 'toGroup']);
351
352
        return $this->performRequest('POST', static::MESSAGES_CREATE_ENDPOINT, [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 352 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createMessage of type Directus\SDK\Response\Entry.
Loading history...
353
            'body' => $data
354
        ]);
355
    }
356
357
    /**
358
     * @inheritdoc
359
     */
360
    public function sendMessage(array $data)
361
    {
362
        return $this->createMessage($data);
363
    }
364
365
    /**
366
     * @inheritdoc
367
     */
368
    public function createPrivileges(array $data)
369
    {
370
        $this->requiredAttributes(['group_id', 'table_name'], $data);
371
372
        return $this->performRequest('POST', static::GROUP_PRIVILEGES_CREATE_ENDPOINT, [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 372 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPrivileges of type Directus\SDK\Response\Entry.
Loading history...
373
            'body' => $data
374
        ]);
375
    }
376
377
    public function createTable($name, array $params = [])
378
    {
379
        $data = [
380
            'addTable' => true,
381
            'table_name' => $name
382
        ];
383
384
        return $this->performRequest('POST', static::TABLE_CREATE_ENDPOINT, [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 384 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createTable of type Directus\SDK\Response\Entry.
Loading history...
385
            'body' => $data
386
        ]);
387
    }
388
389
    /**
390
     * @inheritdoc
391
     */
392
    public function createColumnUIOptions(array $data)
393
    {
394
        $this->requiredAttributes(['table', 'column', 'ui', 'options'], $data);
395
396
        $path = $this->buildPath(static::COLUMN_OPTIONS_CREATE_ENDPOINT, [
397
            $data['table'],
398
            $data['column'],
399
            $data['ui']
400
        ]);
401
402
        $data = ArrayUtils::get($data, 'options');
403
404
        return $this->performRequest('POST', $path, [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...rray('body' => $data)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 404 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...::createColumnUIOptions of type Directus\SDK\Response\Entry.
Loading history...
405
            'body' => $data
406
        ]);
407
    }
408
409
    /**
410
     * @inheritdoc
411
     */
412
    public function getPreferences($table, $user = null)
413
    {
414
        return $this->performRequest('POST', $this->buildPath(static::TABLE_PREFERENCES_ENDPOINT, $table));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('P...CES_ENDPOINT, $table)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 414 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getPreferences of type Directus\SDK\Response\Entry.
Loading history...
415
    }
416
417
    /**
418
     * @inheritdoc
419
     */
420
    public function deleteBookmark($id)
421
    {
422
        return $this->deleteItem('directus_bookmarks', $id);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->deleteItem('directus_bookmarks', $id); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 422 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteBookmark of type Directus\SDK\Response\Entry.
Loading history...
423
    }
424
425
    /**
426
     * @inheritdoc
427
     */
428
    public function deleteColumn($name, $table)
429
    {
430
        $path = $this->buildPath(static::COLUMN_DELETE_ENDPOINT, [$name, $table]);
431
432
        return $this->performRequest('DELETE', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('DELETE', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 432 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteColumn of type Directus\SDK\Response\Entry.
Loading history...
433
    }
434
435
    /**
436
     * @inheritdoc
437
     */
438
    public function deleteGroup($id)
439
    {
440
        return $this->deleteItem('directus_groups', $id);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->deleteItem('directus_groups', $id); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 440 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteGroup of type Directus\SDK\Response\Entry.
Loading history...
441
    }
442
443
    /**
444
     * @inheritdoc
445
     */
446
    public function deleteTable($name)
447
    {
448
        $path = $this->buildPath(static::TABLE_DELETE_ENDPOINT, $name);
449
450
        return $this->performRequest('DELETE', $path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('DELETE', $path); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 450 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteTable of type Directus\SDK\Response\Entry.
Loading history...
451
    }
452
453
    /**
454
     * @inheritdoc
455
     */
456
    public function getActivity(array $params = [])
457
    {
458 View Code Duplication
        if (!ArrayUtils::has($params, 'filters.datetime')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
459
            $params['filters']['datetime'] = ['>=' => DateUtils::daysAgo(30)];
460
        }
461
462
        $path = $this->buildPath(static::ACTIVITY_GET_ENDPOINT);
463
464
        return $this->performRequest('GET', $path, [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->performRequest('G...y('query' => $params)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 464 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getActivity of type Directus\SDK\Response\Entry.
Loading history...
465
            'query' => $params
466
        ]);
467
    }
468
}
469