Completed
Push — d64 ( a462d8...ba0200 )
by Welling
02:05
created

ClientRemote::getMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 1
cp 0
crap 2
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
15
/**
16
 * Client Remote
17
 *
18
 * @author Welling Guzmán <[email protected]>
19
 */
20
class ClientRemote extends BaseClientRemote
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    public function getTables(array $params = [])
26 2
    {
27
        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 27 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTables of type Directus\SDK\Response\EntryCollection.
Loading history...
28 2
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function getTable($tableName)
34 4
    {
35
        $path = $this->buildPath(static::TABLE_INFORMATION_ENDPOINT, $tableName);
36 4
37
        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 37 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTable of type Directus\SDK\Response\Entry.
Loading history...
38 4
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function getColumns($tableName, array $params = [])
44 2
    {
45
        $path = $this->buildPath(static::COLUMN_LIST_ENDPOINT, $tableName);
46 2
47
        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 47 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumns of type Directus\SDK\Response\EntryCollection.
Loading history...
48 2
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function getColumn($tableName, $columnName)
54 2
    {
55
        $path = $this->buildPath(static::COLUMN_INFORMATION_ENDPOINT, [$tableName, $columnName]);
56 2
57
        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 57 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumn of type Directus\SDK\Response\Entry.
Loading history...
58 2
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function getItems($tableName, array $options = [])
64 2
    {
65
        $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...
66 2
67
        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 67 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItems of type Directus\SDK\Response\EntryCollection.
Loading history...
68 2
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function getItem($tableName, $id, array $options = [])
74 2
    {
75
        $path = $this->buildPath(static::TABLE_ENTRY_ENDPOINT, [$tableName, $id]);
76 2
77
        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 77 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItem of type Directus\SDK\Response\Entry.
Loading history...
78 2
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83
    public function getUsers(array $params = [])
84 2
    {
85
        return $this->getItems('directus_users', $params);
86 2
    }
87
88
    /**
89
     * @inheritdoc
90
     */
91
    public function getUser($id, array $params = [])
92 2
    {
93
        return $this->getItem($id, 'directus_users', $params);
94 2
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function getGroups()
100 2
    {
101
        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 101 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroups of type Directus\SDK\Response\EntryCollection.
Loading history...
102 2
    }
103
104
    /**
105
     * @inheritdoc
106
     */
107
    public function getGroup($groupID)
108 2
    {
109
        $path = $this->buildPath(static::GROUP_INFORMATION_ENDPOINT, $groupID);
110 2
111
        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 111 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroup of type Directus\SDK\Response\Entry.
Loading history...
112 2
    }
113
114
    /**
115
     * @inheritdoc
116
     */
117
    public function getGroupPrivileges($groupID)
118 2
    {
119
        $path = $this->buildPath(static::GROUP_PRIVILEGES_ENDPOINT, $groupID);
120 2
121
        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 121 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroupPrivileges of type Directus\SDK\Response\EntryCollection.
Loading history...
122 2
    }
123
124
    /**
125
     * @inheritdoc
126
     */
127
    public function getFiles()
128 2
    {
129
        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 129 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getFiles of type Directus\SDK\Response\EntryCollection.
Loading history...
130 2
    }
131
132
    /**
133
     * @inheritdoc
134
     */
135
    public function getFile($fileID)
136 2
    {
137
        $path = $this->buildPath(static::FILE_INFORMATION_ENDPOINT, $fileID);
138 2
139
        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 139 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getFile of type Directus\SDK\Response\Entry.
Loading history...
140 2
    }
141
142
    /**
143
     * @inheritdoc
144
     */
145
    public function getSettings()
146 2
    {
147
        return $this->performRequest('GET', static::SETTING_LIST_ENDPOINT);
148 2
    }
149
150
    /**
151
     * @inheritdoc
152
     */
153
    public function getSettingsByCollection($collectionName)
154 2
    {
155
        $path = $this->buildPath(static::SETTING_COLLECTION_GET_ENDPOINT, $collectionName);
156 2
157
        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 157 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...getSettingsByCollection of type Directus\SDK\Response\EntryCollection.
Loading history...
158 2
    }
159
160
    /**
161
     * @inheritdoc
162
     */
163
    public function updateSettings($collection, array $data)
164
    {
165
        $path = $this->buildPath(static::SETTING_COLLECTION_UPDATE_ENDPOINT, $collection);
166
167
        return $this->performRequest('PUT', $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 167 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::updateSettings of type Directus\SDK\Response\Entry.
Loading history...
168
            'body' => $data
169
        ]);
170
    }
171
172
    /**
173
     * @inheritdoc
174
     */
175 View Code Duplication
    public function getMessages($userId = null)
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...
176
    {
177
        if ($userId !== null) {
178
            $path = $this->buildPath(static::MESSAGES_USER_LIST_ENDPOINT, $userId);
179
        } else {
180
            $path = $this->buildPath(static::MESSAGES_LIST_ENDPOINT);
181
        }
182
183
        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 183 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getMessages of type Directus\SDK\Response\EntryCollection.
Loading history...
184
    }
185
186
    /**
187
     * @inheritdoc
188
     */
189
    public function getMessage($id)
190
    {
191
        $path = $this->buildPath(static::MESSAGES_GET_ENDPOINT, $id);
192
193
        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 193 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getMessage of type Directus\SDK\Response\Entry.
Loading history...
194
    }
195
196
    /**
197
     * @inheritdoc
198
     */
199 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...
200
    {
201
        $path = $this->buildPath(static::TABLE_ENTRY_CREATE_ENDPOINT, $tableName);
202
        $data = $this->processData($tableName, $data);
203
204
        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 204 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createItem of type Directus\SDK\Response\Entry.
Loading history...
205
    }
206
207
    /**
208
     * @inheritdoc
209
     */
210 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...
211
    {
212
        $path = $this->buildPath(static::TABLE_ENTRY_UPDATE_ENDPOINT, [$tableName, $id]);
213
        $data = $this->processData($tableName, $data);
214
215
        return $this->performRequest('PUT', $path, ['body' => $data]);
216
    }
217
218
    /**
219
     * @inheritdoc
220
     */
221
    public function deleteItem($tableName, $id)
222
    {
223
        $path = $this->buildPath(static::TABLE_ENTRY_DELETE_ENDPOINT, [$tableName, $id]);
224
225
        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...
226
    }
227
228
    /**
229
     * @inheritdoc
230
     */
231
    public function createUser(array $data)
232
    {
233
        return $this->createItem('directus_users', $data);
234
    }
235
236
    /**
237
     * @inheritdoc
238
     */
239
    public function updateUser($id, array $data)
240
    {
241
        return $this->updateItem('directus_users', $id, $data);
242
    }
243
244
    /**
245
     * @inheritdoc
246
     */
247
    public function deleteUser($ids)
248
    {
249
        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...
250
    }
251
252
    /**
253
     * @inheritdoc
254
     */
255
    public function createFile(File $file)
256
    {
257
        $data = $this->processFile($file);
258
259
        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 259 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createFile of type Directus\SDK\Response\Entry.
Loading history...
260
    }
261
262
    /**
263
     * @inheritdoc
264
     */
265
    public function updateFile($id, $data)
266
    {
267
        if ($data instanceof File) {
268
            $data = $data->toArray();
269
        }
270
271
        $data['id'] = $id;
272
        $path = $this->buildPath(static::FILE_UPDATE_ENDPOINT, $id);
273
        $data = $this->processData('directus_files', $data);
274
275
        return $this->performRequest('POST', $path, ['body' => $data]);
276
    }
277
278
    /**
279
     * @inheritdoc
280
     */
281
    public function deleteFile($id)
282
    {
283
        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...
284
    }
285
286
    public function createPreferences($data)
287
    {
288
        $this->requiredAttributes(['title', 'table_name'], $data);
289
290
        $tableName = ArrayUtils::get($data, 'table_name');
291
        $path = $this->buildPath(static::TABLE_PREFERENCES_ENDPOINT, $tableName);
292
        $data = $this->processData($tableName, $data);
293
294
        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 294 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPreferences of type Directus\SDK\Response\Entry.
Loading history...
295
    }
296
297
    /**
298
     * @inheritdoc
299
     */
300
    public function createBookmark($data)
301
    {
302
        $preferences = $this->createPreferences(ArrayUtils::pick($data, [
303
            'title', 'table_name', 'sort', 'status', 'search_string', 'sort_order', 'columns_visible'
304
        ]));
305
306
        $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...
307
        $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...
308
        $bookmarkData = [
309
            'section' => 'search',
310
            'title' => $title,
311
            'url' => 'tables/' . $tableName . '/pref/' . $title
312
        ];
313
314
        $path = $this->buildPath(static::BOOKMARKS_CREATE_ENDPOINT);
315
        $bookmarkData = $this->processData($tableName, $bookmarkData);
316
317
        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 317 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createBookmark of type Directus\SDK\Response\Entry.
Loading history...
318
    }
319
320
    /**
321
     * @inheritdoc
322
     */
323
    public function getBookmark($id)
324
    {
325
        $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...
326
327
        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 327 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getBookmark of type Directus\SDK\Response\Entry.
Loading history...
328
    }
329
330
    /**
331
     * @inheritdoc
332
     */
333 View Code Duplication
    public function getBookmarks($userId = null)
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...
334
    {
335
        if ($userId !== null) {
336
            $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...
337
        } else {
338
            $path = $this->buildPath(static::BOOKMARKS_ALL_ENDPOINT);
339
        }
340
341
        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 341 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getBookmarks of type Directus\SDK\Response\Entry.
Loading history...
342
    }
343
344
    /**
345
     * @inheritdoc
346
     */
347
    public function createColumn($data)
348
    {
349
        $data = $this->parseColumnData($data);
350
351
        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 351 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createColumn of type Directus\SDK\Response\Entry.
Loading history...
352
            'body' => $data
353
        ]);
354
    }
355
356
    /**
357
     * @inheritdoc
358
     */
359
    public function createGroup(array $data)
360
    {
361
        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 361 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createGroup of type Directus\SDK\Response\Entry.
Loading history...
362
            'body' => $data
363
        ]);
364
    }
365
366
    /**
367
     * @inheritdoc
368
     */
369
    public function createMessage(array $data)
370
    {
371
        $this->requiredAttributes(['from', 'message', 'subject'], $data);
372
        $this->requiredOneAttribute(['to', 'toGroup'], $data);
373
374
        $data['recipients'] = $this->getMessagesTo($data);
375
        ArrayUtils::remove($data, ['to', 'toGroup']);
376
377
        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 377 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createMessage of type Directus\SDK\Response\Entry.
Loading history...
378
            'body' => $data
379
        ]);
380
    }
381
382
    /**
383
     * @inheritdoc
384
     */
385
    public function sendMessage(array $data)
386
    {
387
        return $this->createMessage($data);
388
    }
389
390
    /**
391
     * @inheritdoc
392
     */
393
    public function createPrivileges(array $data)
394
    {
395
        $this->requiredAttributes(['group_id', 'table_name'], $data);
396
397
        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 397 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPrivileges of type Directus\SDK\Response\Entry.
Loading history...
398
            'body' => $data
399
        ]);
400
    }
401
402
    public function createTable($name, array $params = [])
403
    {
404
        $data = [
405
            'addTable' => true,
406
            'table_name' => $name
407
        ];
408
409
        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 409 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createTable of type Directus\SDK\Response\Entry.
Loading history...
410
            'body' => $data
411
        ]);
412
    }
413
414
    /**
415
     * @inheritdoc
416
     */
417
    public function createColumnUIOptions(array $data)
418
    {
419
        $this->requiredAttributes(['table', 'column', 'ui', 'options'], $data);
420
421
        $path = $this->buildPath(static::COLUMN_OPTIONS_CREATE_ENDPOINT, [
422
            $data['table'],
423
            $data['column'],
424
            $data['ui']
425
        ]);
426
427
        $data = ArrayUtils::get($data, 'options');
428
429
        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 429 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...::createColumnUIOptions of type Directus\SDK\Response\Entry.
Loading history...
430
            'body' => $data
431
        ]);
432
    }
433
434
    /**
435
     * @inheritdoc
436
     */
437
    public function getPreferences($table, $user = null)
438
    {
439
        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 439 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getPreferences of type Directus\SDK\Response\Entry.
Loading history...
440
    }
441
442
    /**
443
     * @inheritdoc
444
     */
445
    public function deleteBookmark($id)
446
    {
447
        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 447 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteBookmark of type Directus\SDK\Response\Entry.
Loading history...
448
    }
449
450
    /**
451
     * @inheritdoc
452
     */
453
    public function deleteColumn($name, $table)
454
    {
455
        $path = $this->buildPath(static::COLUMN_DELETE_ENDPOINT, [$name, $table]);
456
457
        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 457 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteColumn of type Directus\SDK\Response\Entry.
Loading history...
458
    }
459
460
    /**
461
     * @inheritdoc
462
     */
463
    public function deleteGroup($id)
464
    {
465
        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 465 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteGroup of type Directus\SDK\Response\Entry.
Loading history...
466
    }
467
468
    /**
469 2
     * @inheritdoc
470
     */
471
    public function deleteTable($name)
472
    {
473
        $path = $this->buildPath(static::TABLE_DELETE_ENDPOINT, $name);
474
475
        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 475 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteTable of type Directus\SDK\Response\Entry.
Loading history...
476
    }
477
478
    /**
479
     * @inheritdoc
480
     */
481
    public function getActivity(array $params = [])
482
    {
483 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...
484
            $params['filters']['datetime'] = ['>=' => DateUtils::daysAgo(30)];
485
        }
486
487
        $path = $this->buildPath(static::ACTIVITY_GET_ENDPOINT);
488
489
        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 489 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getActivity of type Directus\SDK\Response\Entry.
Loading history...
490
            'query' => $params
491
        ]);
492
    }
493
}
494