Completed
Push — d64 ( 4484ee...a462d8 )
by Welling
04:55
created

ClientLocal::deleteColumn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 17
loc 17
ccs 0
cts 11
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
13
use Directus\Database\Connection;
14
use Directus\Database\TableGateway\BaseTableGateway;
15
use Directus\Database\TableGateway\DirectusActivityTableGateway;
16
use Directus\Database\TableGateway\DirectusMessagesTableGateway;
17
use Directus\Database\TableGateway\DirectusPreferencesTableGateway;
18
use Directus\Database\TableGateway\DirectusPrivilegesTableGateway;
19
use Directus\Database\TableGateway\DirectusSettingsTableGateway;
20
use Directus\Database\TableGateway\DirectusUiTableGateway;
21
use Directus\Database\TableGateway\DirectusUsersTableGateway;
22
use Directus\Database\TableGateway\RelationalTableGateway;
23
use Directus\Database\TableSchema;
24
use Directus\Util\ArrayUtils;
25
use Directus\Util\DateUtils;
26
use Directus\Util\SchemaUtils;
27
28
/**
29
 * Client Local
30
 *
31
 * Client to Interact with the database directly using Directus Database Component
32
 *
33
 * @author Welling Guzmán <[email protected]>
34
 */
35
class ClientLocal extends AbstractClient
36
{
37
    /**
38
     * @var BaseTableGateway[]
39
     */
40
    protected $tableGateways = [];
41
42
    /**
43
     * @var Connection
44
     */
45
    protected $connection = null;
46
47
    /**
48
     * ClientLocal constructor.
49
     *
50
     * @param $connection
51
     */
52
    public function __construct($connection)
53
    {
54
        $this->connection = $connection;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function getTables(array $params = [])
61
    {
62
        return $this->createResponseFromData(TableSchema::getTablesSchema($params));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFro...TablesSchema($params)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 62 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTables of type Directus\SDK\Response\EntryCollection.
Loading history...
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function getTable($tableName)
69
    {
70
        return $this->createResponseFromData(TableSchema::getSchemaArray($tableName));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFro...hemaArray($tableName)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 70 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTable of type Directus\SDK\Response\Entry.
Loading history...
71
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76
    public function getColumns($tableName, array $params = [])
77
    {
78
        return $this->createResponseFromData(TableSchema::getColumnSchemaArray($tableName, $params));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFro...($tableName, $params)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 78 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumns of type Directus\SDK\Response\EntryCollection.
Loading history...
79
    }
80
81
    /**
82
     * @inheritDoc
83
     */
84
    public function getColumn($tableName, $columnName)
85
    {
86
        return $this->createResponseFromData(TableSchema::getColumnSchema($tableName, $columnName)->toArray());
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFro...olumnName)->toArray()); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 86 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumn of type Directus\SDK\Response\Entry.
Loading history...
87
    }
88
89
    /**
90
     * @inheritDoc
91
     */
92
    public function getItems($tableName, array $params = [])
93
    {
94
        $tableGateway = $this->getTableGateway($tableName);
95
96
        return $this->createResponseFromData($tableGateway->getItems($params));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFro...ay->getItems($params)); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 96 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItems of type Directus\SDK\Response\EntryCollection.
Loading history...
97
    }
98
99
    /**
100
     * @inheritDoc
101
     */
102
    public function getItem($tableName, $id, array $params = [])
103
    {
104
        // @TODO: Dynamic ID
105
        return $this->getItems($tableName, array_merge($params, [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItems($..., array('id' => $id))); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItem of type Directus\SDK\Response\Entry.

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...
106
            'id' => $id
107
        ]));
108
    }
109
110
    /**
111
     * @inheritDoc
112
     */
113
    public function getUsers(array $params = [])
114
    {
115
        // @TODO: store the directus tables somewhere (SchemaManager?)
116
        return $this->getItems('directus_users', $params);
117
    }
118
119
    /**
120
     * @inheritDoc
121
     */
122
    public function getUser($id, array $params = [])
123
    {
124
        return $this->getItem('directus_users', $id, $params);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItem('d..._users', $id, $params); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getUser of type Directus\SDK\Response\Entry.

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...
125
    }
126
127
    /**
128
     * @inheritDoc
129
     */
130
    public function getGroups(array $params = [])
131
    {
132
        return $this->getItems('directus_groups', $params);
133
    }
134
135
    /**
136
     * @inheritDoc
137
     */
138
    public function getGroup($id, array $params = [])
139
    {
140
        return $this->getItem('directus_groups', $id, $params);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItem('d...groups', $id, $params); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getGroup of type Directus\SDK\Response\Entry.

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...
141
    }
142
143
    /**
144
     * @inheritDoc
145
     */
146
    public function getGroupPrivileges($groupID)
147
    {
148
        $this->getItems('directus_privileges', [
149
            'filter' => [
150
                'group_id' => ['eq' => $groupID]
151
            ]
152
        ]);
153
    }
154
155
    /**
156
     * @inheritDoc
157
     */
158
    public function getFiles(array $params = [])
159
    {
160
        return $this->getItems('directus_files', $params);
161
    }
162
163
    /**
164
     * @inheritDoc
165
     */
166
    public function getFile($id, array $params = [])
167
    {
168
        return $this->getItem('directus_files', $id, $params);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItem('d..._files', $id, $params); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getFile of type Directus\SDK\Response\Entry.

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...
169
    }
170
171
    /**
172
     * @inheritDoc
173
     */
174
    public function getSettings()
175
    {
176
        return $this->getItems('directus_settings');
177
    }
178
179
    /**
180
     * @inheritDoc
181
     */
182 View Code Duplication
    public function getSettingsByCollection($collectionName)
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...
183
    {
184
        $connection = $this->container->get('connection');
185
        $acl = $this->container->get('acl');
186
        $tableGateway = new DirectusSettingsTableGateway($connection, $acl);
187
188
        $data = [
189
            'meta' => [
190
                'table' => 'directus_settings',
191
                'type' => 'entry',
192
                'settings_collection' => $collectionName
193
            ],
194
            'data' => $tableGateway->fetchCollection($collectionName)
195
        ];
196
197
        return $this->createResponseFromData($data);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($data); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 197 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...getSettingsByCollection of type Directus\SDK\Response\EntryCollection.
Loading history...
198
    }
199
200
    /**
201
     * @inheritdoc
202
     */
203
    public function updateSettings($collection, array $data)
204
    {
205
        $connection = $this->container->get('connection');
206
        $acl = $this->container->get('acl');
207
        $tableGateway = new DirectusSettingsTableGateway($connection, $acl);
208
209
        $tableGateway->setValues($collection, $data);
210
211
        return $this->getSettingsByCollection($collection);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getSetting...ollection($collection); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::updateSettings of type Directus\SDK\Response\Entry.

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...
212
    }
213
214
    /**
215
     * @inheritDoc
216
     */
217
    public function getMessages($userId)
218
    {
219
        $connection = $this->container->get('connection');
220
        $acl = $this->container->get('acl');
221
        $messagesTableGateway = new DirectusMessagesTableGateway($connection, $acl);
222
        $result = $messagesTableGateway->fetchMessagesInboxWithHeaders($userId);
223
224
        return $this->createResponseFromData($result);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($result); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\Entry to the return on line 224 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getMessages of type Directus\SDK\Response\EntryCollection.
Loading history...
225
    }
226
227
    /**
228
     * @inheritDoc
229
     */
230 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...
231
    {
232
        $tableGateway = $this->getTableGateway($tableName);
233
        $data = $this->processData($tableName, $data);
234
235
        foreach($data as $key => $value) {
236
            if ($value instanceof File) {
237
                $data[$key] = $this->processFile($value);
238
            }
239
        }
240
241
        $newRecord = $tableGateway->manageRecordUpdate($tableName, $data);
242
243
        return $this->getItem($tableName, $newRecord[$tableGateway->primaryKeyFieldName]);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItem($t...>primaryKeyFieldName]); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createItem of type Directus\SDK\Response\Entry.

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...
244
    }
245
246
    /**
247
     * @inheritDoc
248
     */
249 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...
250
    {
251
        $tableGateway = $this->getTableGateway($tableName);
252
        $data = $this->processData($tableName, $data);
253
254
        foreach($data as $key => $value) {
255
            if ($value instanceof File) {
256
                $data[$key] = $this->processFile($value);
257
            }
258
        }
259
260
        $updatedRecord = $tableGateway->manageRecordUpdate($tableName, array_merge($data, ['id' => $id]));
261
262
        return $this->getItem($tableName, $updatedRecord[$tableGateway->primaryKeyFieldName]);
263
    }
264
265
    /**
266
     * @inheritDoc
267
     */
268
    public function deleteItem($tableName, $ids)
269
    {
270
        // @TODO: Accept EntryCollection and Entry
271
        $tableGateway = $this->getTableGateway($tableName);
272
273
        if (!is_array($ids)) {
274
            $ids = [$ids];
275
        }
276
277
        return $tableGateway->delete(function($delete) use ($ids) {
278
            return $delete->where->in('id', $ids);
279
        });
280
    }
281
282
    /**
283
     * @inheritDoc
284
     */
285
    public function createUser(array $data)
286
    {
287
        return $this->createItem('directus_users', $data);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->createItem...irectus_users', $data); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createUser of type Directus\SDK\Response\Entry.

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...
288
    }
289
290
    /**
291
     * @inheritDoc
292
     */
293
    public function updateUser($id, array $data)
294
    {
295
        return $this->updateItem('directus_users', $id, $data);
296
    }
297
298
    /**
299
     * @inheritDoc
300
     */
301
    public function deleteUser($ids)
302
    {
303
        return $this->deleteItem('directus_users', $ids);
304
    }
305
306
    /**
307
     * @inheritDoc
308
     */
309
    public function createFile(File $file)
310
    {
311
        $data = $this->processFile($file);
312
313
        return $this->createItem('directus_files', $data);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->createItem...irectus_files', $data); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createFile of type Directus\SDK\Response\Entry.

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...
314
    }
315
316
    /**
317
     * @inheritDoc
318
     */
319
    public function updateFile($id, $data)
320
    {
321
        if ($data instanceof File) {
322
            $data = $this->processFile($data);
323
        }
324
325
        return $this->updateItem('directus_files', $id, $data);
326
    }
327
328
    /**
329
     * @inheritDoc
330
     */
331
    public function deleteFile($ids)
332
    {
333
        return $this->deleteItem('directus_files', $ids);
334
    }
335
336
    public function createPreferences($data)
337
    {
338
        if (!ArrayUtils::contains($data, ['title', 'table_name'])) {
339
            throw new \Exception('title and table_name are required');
340
        }
341
342
        $acl = $this->container->get('acl');
343
        $data['user'] = $acl->getUserId();
344
345
        return $this->createItem('directus_preferences', $data);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->createItem...s_preferences', $data); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPreferences of type Directus\SDK\Response\Entry.

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...
346
    }
347
348
    /**
349
     * @inheritdoc
350
     */
351
    public function createBookmark($data)
352
    {
353
        $acl = $this->container->get('acl');
354
        $data['user'] = $acl->getUserId();
355
356
        $preferences = $this->createPreferences(ArrayUtils::pick($data, [
357
            'title', 'table_name', 'sort', 'status', 'search_string', 'sort_order', 'columns_visible', 'user'
358
        ]));
359
360
        $title = $preferences->title;
0 ignored issues
show
Bug introduced by
The property title does not seem to exist in Directus\SDK\Response\EntryCollection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
361
        $tableName = $preferences->table_name;
0 ignored issues
show
Bug introduced by
The property table_name does not seem to exist in Directus\SDK\Response\EntryCollection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
362
        $bookmarkData = [
363
            'section' => 'search',
364
            'title' => $title,
365
            'url' => 'tables/' . $tableName . '/pref/' . $title,
366
            'user' => $data['user']
367
        ];
368
369
        return $this->createItem('directus_bookmarks', $bookmarkData);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->createItem...marks', $bookmarkData); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createBookmark of type Directus\SDK\Response\Entry.

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...
370
    }
371
372
    /**
373
     * @inheritdoc
374
     */
375
    public function getBookmark($id)
376
    {
377
        return $this->getItem('directus_bookmarks', $id);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItem('directus_bookmarks', $id); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getBookmark of type Directus\SDK\Response\Entry.

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...
378
    }
379
380
    /**
381
     * @inheritdoc
382
     */
383
    public function getBookmarks($userId = null)
384
    {
385
        $filters = [];
386
        if ($userId !== null) {
387
            $filters = [
388
                'filters' => ['user' => ['eq' => $userId]]
389
            ];
390
        }
391
392
        return $this->getItems('directus_bookmarks', $filters);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getItems('..._bookmarks', $filters); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getBookmarks of type Directus\SDK\Response\Entry.

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...
393
    }
394
395
    /**
396
     * @inheritdoc
397
     */
398
    public function createColumn($data)
399
    {
400
        $data = $this->parseColumnData($data);
401
402
        $tableGateway = $this->getTableGateway($data['table_name']);
403
404
        $tableGateway->addColumn($data['table_name'], ArrayUtils::omit($data, ['table_name']));
405
406
        return $this->getColumn($data['table_name'], $data['column_name']);
407
    }
408
409
    /**
410
     * @inheritdoc
411
     */
412
    public function createGroup(array $data)
413
    {
414
        return $this->createItem('directus_groups', $data);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->createItem...rectus_groups', $data); (Directus\SDK\Response\EntryCollection) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createGroup of type Directus\SDK\Response\Entry.

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...
415
    }
416
417
    /**
418
     * @inheritdoc
419
     */
420
    public function createMessage(array $data)
421
    {
422
        $this->requiredAttributes(['from', 'message', 'subject'], $data);
423
        $this->requiredOneAttribute(['to', 'toGroup'], $data);
424
425
        $recipients = $this->getMessagesTo($data);
426
        $recipients = explode(',', $recipients);
427
        ArrayUtils::remove($data, ['to', 'toGroup']);
428
429
        $groupRecipients = [];
430
        $userRecipients = [];
431
        foreach ($recipients as $recipient) {
432
            $typeAndId = explode('_', $recipient);
433
            if ($typeAndId[0] == 0) {
434
                $userRecipients[] = $typeAndId[1];
435
            } else {
436
                $groupRecipients[] = $typeAndId[1];
437
            }
438
        }
439
440
        $ZendDb = $this->container->get('connection');
441
        $acl = $this->container->get('acl');
442
        if (count($groupRecipients) > 0) {
443
            $usersTableGateway = new DirectusUsersTableGateway($ZendDb, $acl);
444
            $result = $usersTableGateway->findActiveUserIdsByGroupIds($groupRecipients);
445
            foreach ($result as $item) {
446
                $userRecipients[] = $item['id'];
447
            }
448
        }
449
450
        $userRecipients[] = $acl->getUserId();
451
452
        $messagesTableGateway = new DirectusMessagesTableGateway($ZendDb, $acl);
453
        $id = $messagesTableGateway->sendMessage($data, array_unique($userRecipients), $acl->getUserId());
454
455
        if ($id) {
456
            $Activity = new DirectusActivityTableGateway($ZendDb, $acl);
457
            $data['id'] = $id;
458
            $Activity->recordMessage($data, $acl->getUserId());
459
        }
460
461
        $message = $messagesTableGateway->fetchMessageWithRecipients($id, $acl->getUserId());
462
        $response = [
463
            'meta' => [
464
                'type' => 'item',
465
                'table' => 'directus_messages'
466
            ],
467
            'data' => $message
468
        ];
469
470
        return $this->createResponseFromData($response);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($response); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 470 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createMessage of type Directus\SDK\Response\Entry.
Loading history...
471
    }
472
473
    /**
474
     * @inheritdoc
475
     */
476
    public function sendMessage(array $data)
477
    {
478
        return $this->createMessage($data);
479
    }
480
481 View Code Duplication
    public function createPrivileges(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...
482
    {
483
        $connection = $this->container->get('connection');
484
        $acl = $this->container->get('acl');
485
        $privileges = new DirectusPrivilegesTableGateway($connection, $acl);
486
487
        $response = [
488
            'meta' => [
489
                'type' => 'item',
490
                'table' => 'directus_privileges'
491
            ],
492
            'data' => $privileges->insertPrivilege($data)
493
        ];
494
495
        return $this->createResponseFromData($response);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($response); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 495 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPrivileges of type Directus\SDK\Response\Entry.
Loading history...
496
    }
497
498
    public function createTable($name, array $data = [])
499
    {
500
        $isTableNameAlphanumeric = preg_match("/[a-z0-9]+/i", $name);
501
        $zeroOrMoreUnderscoresDashes = preg_match("/[_-]*/i", $name);
502
503
        if (!($isTableNameAlphanumeric && $zeroOrMoreUnderscoresDashes)) {
504
            return $this->createResponseFromData(['error' => ['message' => 'invalid_table_name']]);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFro...invalid_table_name'))); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 504 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createTable of type Directus\SDK\Response\Entry.
Loading history...
505
        }
506
507
        $schema = $this->container->get('schemaManager');
508
        $emitter = $this->container->get('emitter');
509
        if (!$schema->tableExists($name)) {
510
            $emitter->run('table.create:before', $name);
511
            // Through API:
512
            // Remove spaces and symbols from table name
513
            // And in lowercase
514
            $name = SchemaUtils::cleanTableName($name);
515
            $schema->createTable($name);
516
            $emitter->run('table.create', $name);
517
            $emitter->run('table.create:after', $name);
518
        }
519
520
        $connection = $this->container->get('connection');
521
        $acl = $this->container->get('acl');
522
        $privileges = new DirectusPrivilegesTableGateway($connection, $acl);
523
524
        return $this->createResponseFromData($privileges->insertPrivilege([
1 ignored issue
show
Bug Compatibility introduced by
The expression $this->createResponseFro...able_name' => $name))); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 524 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createTable of type Directus\SDK\Response\Entry.
Loading history...
525
            'group_id' => 1,
526
            'table_name' => $name
527
        ]));
528
    }
529
530
    /**
531
     * @inheritdoc
532
     */
533
    public function createColumnUIOptions(array $data)
534
    {
535
        $this->requiredAttributes(['table', 'column', 'ui', 'options'], $data);
536
        $tableGateway = $this->getTableGateway('directus_ui');
537
538
        $table = $data['table'];
539
        $column = $data['column'];
540
        $ui = $data['ui'];
541
542
        $data = $data['options'];
543
        $keys = ['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui];
544
        $uis = to_name_value($data, $keys);
545
546
        $column_settings = [];
547
        foreach ($uis as $col) {
548
            $existing = $tableGateway->select(['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']])->toArray();
549
            if (count($existing) > 0) {
550
                $col['id'] = $existing[0]['id'];
551
            }
552
            array_push($column_settings, $col);
553
        }
554
        $tableGateway->updateCollection($column_settings);
555
556
        $connection = $this->container->get('connection');
557
        $acl = $this->container->get('acl');
558
        $UiOptions = new DirectusUiTableGateway($connection, $acl);
559
        $response = $UiOptions->fetchOptions($table, $column, $ui);
560
561
        if (!$response) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $response of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
562
            $response = [
563
                'error' => [
564
                    'message' => sprintf('unable_to_find_column_%s_options_for_%s', ['column' => $column, 'ui' => $ui])
565
                ],
566
                'success' => false
567
            ];
568
        } else {
569
            $response = [
570
                'meta' => [
571
                    'type' => 'item',
572
                    'table' => 'directus_ui'
573
                ],
574
                'data' => $response
575
            ];
576
        }
577
578
        return $this->createResponseFromData($response);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($response); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 578 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...::createColumnUIOptions of type Directus\SDK\Response\Entry.
Loading history...
579
    }
580
581 View Code Duplication
    public function getPreferences($table, $user)
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...
582
    {
583
        $acl = $this->container->get('acl');
584
        $connection = $this->container->get('connection');
585
        $preferencesTableGateway = new DirectusPreferencesTableGateway($connection, $acl);
586
587
        $response = [
588
            'meta' => [
589
                'type' => 'item',
590
                'table' => 'directus_preferences'
591
            ],
592
            'data' => $preferencesTableGateway->fetchByUserAndTableAndTitle($user, $table)
593
        ];
594
595
        return $this->createResponseFromData($response);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($response); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 595 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getPreferences of type Directus\SDK\Response\Entry.
Loading history...
596
    }
597
598
    /**
599
     * @inheritdoc
600
     */
601
    public function deleteBookmark($id)
602
    {
603
        return $this->deleteItem('directus_bookmarks', $id);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deleteItem...ectus_bookmarks', $id); (integer) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteBookmark of type Directus\SDK\Response\Entry.

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...
604
    }
605
606
    /**
607
     * @inheritdoc
608
     */
609 View Code Duplication
    public function deleteColumn($name, $table)
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...
610
    {
611
        $tableGateway = $this->getTableGateway($table);
612
        $success = $tableGateway->dropColumn($name);
613
614
        $response = [
615
            'success' => (bool) $success
616
        ];
617
618
        if (!$success) {
619
            $response['error'] = [
620
                'message' => sprintf('unable_to_remove_column_%s', ['column_name' => $name])
621
            ];
622
        }
623
624
        return $this->createResponseFromData($response);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($response); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 624 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteColumn of type Directus\SDK\Response\Entry.
Loading history...
625
    }
626
627
    /**
628
     * @inheritdoc
629
     */
630
    public function deleteGroup($id)
631
    {
632
        return $this->deleteItem('directus_groups', $id);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->deleteItem('directus_groups', $id); (integer) is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteGroup of type Directus\SDK\Response\Entry.

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...
633
    }
634
635
    /**
636
     * @inheritdoc
637
     */
638 View Code Duplication
    public function deleteTable($name)
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...
639
    {
640
        $tableGateway = $this->getTableGateway($name);
641
        $success = $tableGateway->drop();
642
643
        $response = [
644
            'success' => (bool) $success
645
        ];
646
647
        if (!$success) {
648
            $response['error'] = [
649
                'message' => sprintf('unable_to_remove_table_%s', ['table_name' => $name])
650
            ];
651
        }
652
653
        return $this->createResponseFromData($response);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($response); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 653 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteTable of type Directus\SDK\Response\Entry.
Loading history...
654
    }
655
656
    public function getActivity(array $params = [])
657
    {
658
        $connection = $this->container->get('connection');
659
        $acl = $this->container->get('acl');
660
        $tableGateway = new DirectusActivityTableGateway($connection, $acl);
661 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...
662
            $params['filters']['datetime'] = ['>=' => DateUtils::daysAgo(30)];
663
        }
664
665
        $data = $tableGateway->fetchFeed($params);
666
667
        return $this->createResponseFromData($data);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->createResponseFromData($data); of type Directus\SDK\Response\En...ctus\SDK\Response\Entry adds the type Directus\SDK\Response\EntryCollection to the return on line 667 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getActivity of type Directus\SDK\Response\Entry.
Loading history...
668
    }
669
670
    /**
671
     * Get a table gateway for the given table name
672
     *
673
     * @param $tableName
674
     *
675
     * @return RelationalTableGateway
676
     */
677
    protected function getTableGateway($tableName)
678
    {
679
        if (!array_key_exists($tableName, $this->tableGateways)) {
680
            $acl = TableSchema::getAclInstance();
681
            $this->tableGateways[$tableName] = new RelationalTableGateway($tableName, $this->connection, $acl);
682
        }
683
684
        return $this->tableGateways[$tableName];
685
    }
686
}
687