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

ClientLocal   D

Complexity

Total Complexity 67

Size/Duplication

Total Lines 629
Duplicated Lines 15.74 %

Coupling/Cohesion

Components 1
Dependencies 14

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 99
loc 629
ccs 0
cts 391
cp 0
rs 4.1221
c 0
b 0
f 0
wmc 67
lcom 1
cbo 14

44 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTables() 0 4 1
A getTable() 0 4 1
A getColumns() 0 4 1
A getColumn() 0 4 1
A getItems() 0 6 1
A getItem() 0 7 1
A getUsers() 0 5 1
A getUser() 0 4 1
A getGroups() 0 4 1
A getGroup() 0 4 1
A getGroupPrivileges() 0 8 1
A getFiles() 0 4 1
A getFile() 0 4 1
A getSettings() 0 4 1
A getSettingsByCollection() 0 8 1
A getMessages() 0 9 1
A createItem() 15 15 3
A updateItem() 15 15 3
A deleteItem() 0 13 2
A createUser() 0 4 1
A updateUser() 0 4 1
A deleteUser() 0 4 1
A createFile() 0 6 1
A updateFile() 0 8 2
A deleteFile() 0 4 1
A createPreferences() 0 11 2
A createBookmark() 0 20 1
A getBookmark() 0 4 1
A getBookmarks() 0 11 2
A createColumn() 0 10 1
A createGroup() 0 4 1
B createMessage() 0 52 6
A sendMessage() 0 4 1
A createPrivileges() 16 16 1
B createTable() 0 31 4
B createColumnUIOptions() 0 47 4
A getPreferences() 16 16 1
A deleteBookmark() 0 4 1
A deleteColumn() 17 17 2
A deleteGroup() 0 4 1
A deleteTable() 17 17 2
A getActivity() 3 13 2
A getTableGateway() 0 9 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ClientLocal often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ClientLocal, and based on these observations, apply Extract Interface, too.

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\DirectusUiTableGateway;
20
use Directus\Database\TableGateway\DirectusUsersTableGateway;
21
use Directus\Database\TableGateway\RelationalTableGateway;
22
use Directus\Database\TableSchema;
23
use Directus\Util\ArrayUtils;
24
use Directus\Util\DateUtils;
25
use Directus\Util\SchemaUtils;
26
27
/**
28
 * Client Local
29
 *
30
 * Client to Interact with the database directly using Directus Database Component
31
 *
32
 * @author Welling Guzmán <[email protected]>
33
 */
34
class ClientLocal extends AbstractClient
35
{
36
    /**
37
     * @var BaseTableGateway[]
38
     */
39
    protected $tableGateways = [];
40
41
    /**
42
     * @var Connection
43
     */
44
    protected $connection = null;
45
46
    /**
47
     * ClientLocal constructor.
48
     *
49
     * @param $connection
50
     */
51
    public function __construct($connection)
52
    {
53
        $this->connection = $connection;
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function getTables(array $params = [])
60
    {
61
        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 61 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTables of type Directus\SDK\Response\EntryCollection.
Loading history...
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function getTable($tableName)
68
    {
69
        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 69 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getTable of type Directus\SDK\Response\Entry.
Loading history...
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function getColumns($tableName, array $params = [])
76
    {
77
        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 77 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumns of type Directus\SDK\Response\EntryCollection.
Loading history...
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    public function getColumn($tableName, $columnName)
84
    {
85
        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 85 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getColumn of type Directus\SDK\Response\Entry.
Loading history...
86
    }
87
88
    /**
89
     * @inheritDoc
90
     */
91
    public function getItems($tableName, array $params = [])
92
    {
93
        $tableGateway = $this->getTableGateway($tableName);
94
95
        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 95 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getItems of type Directus\SDK\Response\EntryCollection.
Loading history...
96
    }
97
98
    /**
99
     * @inheritDoc
100
     */
101
    public function getItem($tableName, $id, array $params = [])
102
    {
103
        // @TODO: Dynamic ID
104
        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...
105
            'id' => $id
106
        ]));
107
    }
108
109
    /**
110
     * @inheritDoc
111
     */
112
    public function getUsers(array $params = [])
113
    {
114
        // @TODO: store the directus tables somewhere (SchemaManager?)
115
        return $this->getItems('directus_users', $params);
116
    }
117
118
    /**
119
     * @inheritDoc
120
     */
121
    public function getUser($id, array $params = [])
122
    {
123
        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...
124
    }
125
126
    /**
127
     * @inheritDoc
128
     */
129
    public function getGroups(array $params = [])
130
    {
131
        return $this->getItems('directus_groups', $params);
132
    }
133
134
    /**
135
     * @inheritDoc
136
     */
137
    public function getGroup($id, array $params = [])
138
    {
139
        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...
140
    }
141
142
    /**
143
     * @inheritDoc
144
     */
145
    public function getGroupPrivileges($groupID)
146
    {
147
        $this->getItems('directus_privileges', [
148
            'filter' => [
149
                'group_id' => ['eq' => $groupID]
150
            ]
151
        ]);
152
    }
153
154
    /**
155
     * @inheritDoc
156
     */
157
    public function getFiles(array $params = [])
158
    {
159
        return $this->getItems('directus_files', $params);
160
    }
161
162
    /**
163
     * @inheritDoc
164
     */
165
    public function getFile($id, array $params = [])
166
    {
167
        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...
168
    }
169
170
    /**
171
     * @inheritDoc
172
     */
173
    public function getSettings()
174
    {
175
        return $this->getItems('directus_settings');
176
    }
177
178
    /**
179
     * @inheritDoc
180
     */
181
    public function getSettingsByCollection($collectionName)
182
    {
183
        return $this->getItems('directus_settings', [
184
            'filter' => [
185
                'collection' => ['eq' => $collectionName]
186
            ]
187
        ]);
188
    }
189
190
    /**
191
     * @inheritDoc
192
     */
193
    public function getMessages($userId)
194
    {
195
        $connection = $this->container->get('connection');
196
        $acl = $this->container->get('acl');
197
        $messagesTableGateway = new DirectusMessagesTableGateway($connection, $acl);
198
        $result = $messagesTableGateway->fetchMessagesInboxWithHeaders($userId);
199
200
        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 200 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getMessages of type Directus\SDK\Response\EntryCollection.
Loading history...
201
    }
202
203
    /**
204
     * @inheritDoc
205
     */
206 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...
207
    {
208
        $tableGateway = $this->getTableGateway($tableName);
209
        $data = $this->processData($tableName, $data);
210
211
        foreach($data as $key => $value) {
212
            if ($value instanceof File) {
213
                $data[$key] = $this->processFile($value);
214
            }
215
        }
216
217
        $newRecord = $tableGateway->manageRecordUpdate($tableName, $data);
218
219
        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...
220
    }
221
222
    /**
223
     * @inheritDoc
224
     */
225 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...
226
    {
227
        $tableGateway = $this->getTableGateway($tableName);
228
        $data = $this->processData($tableName, $data);
229
230
        foreach($data as $key => $value) {
231
            if ($value instanceof File) {
232
                $data[$key] = $this->processFile($value);
233
            }
234
        }
235
236
        $updatedRecord = $tableGateway->manageRecordUpdate($tableName, array_merge($data, ['id' => $id]));
237
238
        return $this->getItem($tableName, $updatedRecord[$tableGateway->primaryKeyFieldName]);
239
    }
240
241
    /**
242
     * @inheritDoc
243
     */
244
    public function deleteItem($tableName, $ids)
245
    {
246
        // @TODO: Accept EntryCollection and Entry
247
        $tableGateway = $this->getTableGateway($tableName);
248
249
        if (!is_array($ids)) {
250
            $ids = [$ids];
251
        }
252
253
        return $tableGateway->delete(function($delete) use ($ids) {
254
            return $delete->where->in('id', $ids);
255
        });
256
    }
257
258
    /**
259
     * @inheritDoc
260
     */
261
    public function createUser(array $data)
262
    {
263
        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...
264
    }
265
266
    /**
267
     * @inheritDoc
268
     */
269
    public function updateUser($id, array $data)
270
    {
271
        return $this->updateItem('directus_users', $id, $data);
272
    }
273
274
    /**
275
     * @inheritDoc
276
     */
277
    public function deleteUser($ids)
278
    {
279
        return $this->deleteItem('directus_users', $ids);
280
    }
281
282
    /**
283
     * @inheritDoc
284
     */
285
    public function createFile(File $file)
286
    {
287
        $data = $this->processFile($file);
288
289
        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...
290
    }
291
292
    /**
293
     * @inheritDoc
294
     */
295
    public function updateFile($id, $data)
296
    {
297
        if ($data instanceof File) {
298
            $data = $this->processFile($data);
299
        }
300
301
        return $this->updateItem('directus_files', $id, $data);
302
    }
303
304
    /**
305
     * @inheritDoc
306
     */
307
    public function deleteFile($ids)
308
    {
309
        return $this->deleteItem('directus_files', $ids);
310
    }
311
312
    public function createPreferences($data)
313
    {
314
        if (!ArrayUtils::contains($data, ['title', 'table_name'])) {
315
            throw new \Exception('title and table_name are required');
316
        }
317
318
        $acl = $this->container->get('acl');
319
        $data['user'] = $acl->getUserId();
320
321
        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...
322
    }
323
324
    /**
325
     * @inheritdoc
326
     */
327
    public function createBookmark($data)
328
    {
329
        $acl = $this->container->get('acl');
330
        $data['user'] = $acl->getUserId();
331
332
        $preferences = $this->createPreferences(ArrayUtils::pick($data, [
333
            'title', 'table_name', 'sort', 'status', 'search_string', 'sort_order', 'columns_visible', 'user'
334
        ]));
335
336
        $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...
337
        $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...
338
        $bookmarkData = [
339
            'section' => 'search',
340
            'title' => $title,
341
            'url' => 'tables/' . $tableName . '/pref/' . $title,
342
            'user' => $data['user']
343
        ];
344
345
        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...
346
    }
347
348
    /**
349
     * @inheritdoc
350
     */
351
    public function getBookmark($id)
352
    {
353
        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...
354
    }
355
356
    /**
357
     * @inheritdoc
358
     */
359
    public function getBookmarks($userId = null)
360
    {
361
        $filters = [];
362
        if ($userId !== null) {
363
            $filters = [
364
                'filters' => ['user' => ['eq' => $userId]]
365
            ];
366
        }
367
368
        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...
369
    }
370
371
    /**
372
     * @inheritdoc
373
     */
374
    public function createColumn($data)
375
    {
376
        $data = $this->parseColumnData($data);
377
378
        $tableGateway = $this->getTableGateway($data['table_name']);
379
380
        $tableGateway->addColumn($data['table_name'], ArrayUtils::omit($data, ['table_name']));
381
382
        return $this->getColumn($data['table_name'], $data['column_name']);
383
    }
384
385
    /**
386
     * @inheritdoc
387
     */
388
    public function createGroup(array $data)
389
    {
390
        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...
391
    }
392
393
    /**
394
     * @inheritdoc
395
     */
396
    public function createMessage(array $data)
397
    {
398
        $this->requiredAttributes(['from', 'message', 'subject'], $data);
399
        $this->requiredOneAttribute(['to', 'toGroup'], $data);
400
401
        $recipients = $this->getMessagesTo($data);
402
        $recipients = explode(',', $recipients);
403
        ArrayUtils::remove($data, ['to', 'toGroup']);
404
405
        $groupRecipients = [];
406
        $userRecipients = [];
407
        foreach ($recipients as $recipient) {
408
            $typeAndId = explode('_', $recipient);
409
            if ($typeAndId[0] == 0) {
410
                $userRecipients[] = $typeAndId[1];
411
            } else {
412
                $groupRecipients[] = $typeAndId[1];
413
            }
414
        }
415
416
        $ZendDb = $this->container->get('connection');
417
        $acl = $this->container->get('acl');
418
        if (count($groupRecipients) > 0) {
419
            $usersTableGateway = new DirectusUsersTableGateway($ZendDb, $acl);
420
            $result = $usersTableGateway->findActiveUserIdsByGroupIds($groupRecipients);
421
            foreach ($result as $item) {
422
                $userRecipients[] = $item['id'];
423
            }
424
        }
425
426
        $userRecipients[] = $acl->getUserId();
427
428
        $messagesTableGateway = new DirectusMessagesTableGateway($ZendDb, $acl);
429
        $id = $messagesTableGateway->sendMessage($data, array_unique($userRecipients), $acl->getUserId());
430
431
        if ($id) {
432
            $Activity = new DirectusActivityTableGateway($ZendDb, $acl);
433
            $data['id'] = $id;
434
            $Activity->recordMessage($data, $acl->getUserId());
435
        }
436
437
        $message = $messagesTableGateway->fetchMessageWithRecipients($id, $acl->getUserId());
438
        $response = [
439
            'meta' => [
440
                'type' => 'item',
441
                'table' => 'directus_messages'
442
            ],
443
            'data' => $message
444
        ];
445
446
        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 446 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createMessage of type Directus\SDK\Response\Entry.
Loading history...
447
    }
448
449
    /**
450
     * @inheritdoc
451
     */
452
    public function sendMessage(array $data)
453
    {
454
        return $this->createMessage($data);
455
    }
456
457 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...
458
    {
459
        $connection = $this->container->get('connection');
460
        $acl = $this->container->get('acl');
461
        $privileges = new DirectusPrivilegesTableGateway($connection, $acl);
462
463
        $response = [
464
            'meta' => [
465
                'type' => 'item',
466
                'table' => 'directus_privileges'
467
            ],
468
            'data' => $privileges->insertPrivilege($data)
469
        ];
470
471
        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 471 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createPrivileges of type Directus\SDK\Response\Entry.
Loading history...
472
    }
473
474
    public function createTable($name, array $data = [])
475
    {
476
        $isTableNameAlphanumeric = preg_match("/[a-z0-9]+/i", $name);
477
        $zeroOrMoreUnderscoresDashes = preg_match("/[_-]*/i", $name);
478
479
        if (!($isTableNameAlphanumeric && $zeroOrMoreUnderscoresDashes)) {
480
            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 480 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createTable of type Directus\SDK\Response\Entry.
Loading history...
481
        }
482
483
        $schema = $this->container->get('schemaManager');
484
        $emitter = $this->container->get('emitter');
485
        if (!$schema->tableExists($name)) {
486
            $emitter->run('table.create:before', $name);
487
            // Through API:
488
            // Remove spaces and symbols from table name
489
            // And in lowercase
490
            $name = SchemaUtils::cleanTableName($name);
491
            $schema->createTable($name);
492
            $emitter->run('table.create', $name);
493
            $emitter->run('table.create:after', $name);
494
        }
495
496
        $connection = $this->container->get('connection');
497
        $acl = $this->container->get('acl');
498
        $privileges = new DirectusPrivilegesTableGateway($connection, $acl);
499
500
        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 500 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::createTable of type Directus\SDK\Response\Entry.
Loading history...
501
            'group_id' => 1,
502
            'table_name' => $name
503
        ]));
504
    }
505
506
    /**
507
     * @inheritdoc
508
     */
509
    public function createColumnUIOptions(array $data)
510
    {
511
        $this->requiredAttributes(['table', 'column', 'ui', 'options'], $data);
512
        $tableGateway = $this->getTableGateway('directus_ui');
513
514
        $table = $data['table'];
515
        $column = $data['column'];
516
        $ui = $data['ui'];
517
518
        $data = $data['options'];
519
        $keys = ['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui];
520
        $uis = to_name_value($data, $keys);
521
522
        $column_settings = [];
523
        foreach ($uis as $col) {
524
            $existing = $tableGateway->select(['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']])->toArray();
525
            if (count($existing) > 0) {
526
                $col['id'] = $existing[0]['id'];
527
            }
528
            array_push($column_settings, $col);
529
        }
530
        $tableGateway->updateCollection($column_settings);
531
532
        $connection = $this->container->get('connection');
533
        $acl = $this->container->get('acl');
534
        $UiOptions = new DirectusUiTableGateway($connection, $acl);
535
        $response = $UiOptions->fetchOptions($table, $column, $ui);
536
537
        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...
538
            $response = [
539
                'error' => [
540
                    'message' => sprintf('unable_to_find_column_%s_options_for_%s', ['column' => $column, 'ui' => $ui])
541
                ],
542
                'success' => false
543
            ];
544
        } else {
545
            $response = [
546
                'meta' => [
547
                    'type' => 'item',
548
                    'table' => 'directus_ui'
549
                ],
550
                'data' => $response
551
            ];
552
        }
553
554
        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 554 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInt...::createColumnUIOptions of type Directus\SDK\Response\Entry.
Loading history...
555
    }
556
557 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...
558
    {
559
        $acl = $this->container->get('acl');
560
        $connection = $this->container->get('connection');
561
        $preferencesTableGateway = new DirectusPreferencesTableGateway($connection, $acl);
562
563
        $response = [
564
            'meta' => [
565
                'type' => 'item',
566
                'table' => 'directus_preferences'
567
            ],
568
            'data' => $preferencesTableGateway->fetchByUserAndTableAndTitle($user, $table)
569
        ];
570
571
        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 571 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getPreferences of type Directus\SDK\Response\Entry.
Loading history...
572
    }
573
574
    /**
575
     * @inheritdoc
576
     */
577
    public function deleteBookmark($id)
578
    {
579
        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...
580
    }
581
582
    /**
583
     * @inheritdoc
584
     */
585 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...
586
    {
587
        $tableGateway = $this->getTableGateway($table);
588
        $success = $tableGateway->dropColumn($name);
589
590
        $response = [
591
            'success' => (bool) $success
592
        ];
593
594
        if (!$success) {
595
            $response['error'] = [
596
                'message' => sprintf('unable_to_remove_column_%s', ['column_name' => $name])
597
            ];
598
        }
599
600
        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 600 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteColumn of type Directus\SDK\Response\Entry.
Loading history...
601
    }
602
603
    /**
604
     * @inheritdoc
605
     */
606
    public function deleteGroup($id)
607
    {
608
        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...
609
    }
610
611
    /**
612
     * @inheritdoc
613
     */
614 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...
615
    {
616
        $tableGateway = $this->getTableGateway($name);
617
        $success = $tableGateway->drop();
618
619
        $response = [
620
            'success' => (bool) $success
621
        ];
622
623
        if (!$success) {
624
            $response['error'] = [
625
                'message' => sprintf('unable_to_remove_table_%s', ['table_name' => $name])
626
            ];
627
        }
628
629
        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 629 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::deleteTable of type Directus\SDK\Response\Entry.
Loading history...
630
    }
631
632
    public function getActivity(array $params = [])
633
    {
634
        $connection = $this->container->get('connection');
635
        $acl = $this->container->get('acl');
636
        $tableGateway = new DirectusActivityTableGateway($connection, $acl);
637 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...
638
            $params['filters']['datetime'] = ['>=' => DateUtils::daysAgo(30)];
639
        }
640
641
        $data = $tableGateway->fetchFeed($params);
642
643
        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 643 which is incompatible with the return type declared by the interface Directus\SDK\RequestsInterface::getActivity of type Directus\SDK\Response\Entry.
Loading history...
644
    }
645
646
    /**
647
     * Get a table gateway for the given table name
648
     *
649
     * @param $tableName
650
     *
651
     * @return RelationalTableGateway
652
     */
653
    protected function getTableGateway($tableName)
654
    {
655
        if (!array_key_exists($tableName, $this->tableGateways)) {
656
            $acl = TableSchema::getAclInstance();
657
            $this->tableGateways[$tableName] = new RelationalTableGateway($tableName, $this->connection, $acl);
658
        }
659
660
        return $this->tableGateways[$tableName];
661
    }
662
}
663