LearningLocker   F
last analyzed

Complexity

Total Complexity 108

Size/Duplication

Total Lines 475
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 108
eloc 160
c 2
b 0
f 0
dl 0
loc 475
rs 2

31 Methods

Rating   Name   Duplication   Size   Complexity  
A routes() 0 3 1
A journeys() 0 6 2
A organisation() 0 6 2
A journeyProgress() 0 6 4
A client() 0 5 4
A query() 0 6 4
A personas() 0 6 2
A user() 0 6 4
A dashboards() 0 6 2
A role() 0 6 4
A export() 0 6 4
A stores() 0 6 2
A roles() 0 6 2
A persona() 0 6 4
A downloads() 0 6 2
A statement() 0 6 2
A exports() 0 6 2
A dashboard() 0 6 4
A statementForwarding() 0 6 2
A visualisations() 0 6 2
A store() 0 6 4
A users() 0 6 2
A connect() 0 6 2
A __construct() 0 2 1
A download() 0 6 2
D api() 0 47 28
A statements() 0 6 2
A queries() 0 6 2
A clients() 0 6 2
A visualisation() 0 6 4
A journey() 0 6 4

How to fix   Complexity   

Complex Class

Complex classes like LearningLocker 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.

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 LearningLocker, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Ijeffro\Laralocker;
4
5
use Ijeffro\Laralocker\LearningLocker\Connection;
6
use Ijeffro\Laralocker\LearningLocker\Roles\RoleHandler;
7
use Ijeffro\Laralocker\LearningLocker\Users\UserHandler;
8
use Ijeffro\Laralocker\LearningLocker\Stores\StoreHandler;
9
use Ijeffro\Laralocker\LearningLocker\Queries\QueryHandler;
10
use Ijeffro\Laralocker\LearningLocker\Client\ClientHandler;
11
use Ijeffro\Laralocker\LearningLocker\Exports\ExportHandler;
12
use Ijeffro\Laralocker\LearningLocker\Personas\PersonaHandler;
13
use Ijeffro\Laralocker\LearningLocker\Journeys\JourneyHandler;
14
use Ijeffro\Laralocker\LearningLocker\Downloads\DownloadHandler;
15
use Ijeffro\Laralocker\LearningLocker\Statements\StatementHandler;
16
use Ijeffro\Laralocker\LearningLocker\Dashboards\DashboardHandler;
17
use Ijeffro\Laralocker\LearningLocker\Organisation\OrganisationHandler;
18
use Ijeffro\Laralocker\LearningLocker\Visualisations\VisualisationHandler;
19
use Ijeffro\Laralocker\LearningLocker\JourneyProgress\JourneyProgressHandler;
20
use Ijeffro\Laralocker\LearningLocker\StatementForwarding\StatementForwardingHandler;
21
22
class LearningLocker {
23
24
    public $api;
25
    public $user;
26
    public $role;
27
    public $users;
28
    public $roles;
29
    public $store;
30
    public $query;
31
    public $stores;
32
    public $export;
33
    public $client;
34
    public $exports;
35
    public $clients;
36
    public $queries;
37
    public $persona;
38
    public $journey;
39
    public $personas;
40
    public $journeys;
41
    public $download;
42
    public $downloads;
43
    public $dashboard;
44
    public $statement;
45
    public $dashboards;
46
    public $statements;
47
    public $connection;
48
    public $aggregation;
49
    public $organisation;
50
    public $organisations;
51
    public $visualisation;
52
    public $visualisations;
53
    public $journey_progress;
54
    public $statement_forwarding;
55
56
    public function __construct($key = null, $secret = null, $url = null)
0 ignored issues
show
Unused Code introduced by ijeffro
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    public function __construct(/** @scrutinizer ignore-unused */ $key = null, $secret = null, $url = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by ijeffro
The parameter $url is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    public function __construct($key = null, $secret = null, /** @scrutinizer ignore-unused */ $url = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by ijeffro
The parameter $secret is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    public function __construct($key = null, /** @scrutinizer ignore-unused */ $secret = null, $url = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
59
    }
60
61
    /**
62
     * Learning Locker API: Connect
63
     *
64
     * @return Connection
65
     */
66
    public function connect($key, $secret, $url)
67
    {
68
        if ($this->connection) return $this;
0 ignored issues
show
Bug Best Practice introduced by ijeffro
The expression return $this returns the type Ijeffro\Laralocker\LearningLocker which is incompatible with the documented return type Ijeffro\Laralocker\LearningLocker\Connection.
Loading history...
69
70
        $this->connection = new Connection($key, $secret, $url);
71
        return $this->connect($key, $secret, $url);
72
    }
73
74
    /**
75
     * Learning Locker API: Clients
76
     *
77
     * @return ClientHandler
78
     */
79
    public function clients()
80
    {
81
        if ($this->clients) return $this->clients;
82
83
        $this->clients = new ClientHandler;
84
        return $this->clients();
85
    }
86
87
    /**
88
     * Learning Locker API: Client
89
     *
90
     * @param $id
91
     * @return ClientHandler
92
     */
93
    public function client($id = null)
94
    {
95
        if ($this->client) return $this->client;
96
        $this->client = new ClientHandler($id ? $id : null);
97
        return $this->client($id ? $id : null);
98
    }
99
100
    /**
101
     * Learning Locker API: Users
102
     *
103
     * @return UserHandler
104
     */
105
    public function users()
106
    {
107
        if ($this->users) return $this->users;
108
109
        $this->users = new UserHandler;
110
        return $this->users();
111
    }
112
113
    /**
114
     * Learning Locker API: User
115
     *
116
     * @param $id
117
     * @return UserHandler
118
     */
119
    public function user($id = null)
120
    {
121
        if ($this->user) return $this->user;
122
123
        $this->user = new UserHandler($id ? $id : null);
124
        return $this->user($id ? $id : null);
125
    }
126
127
    /**
128
     * Learning Locker API: Roles
129
     *
130
     * @return RoleHandler
131
     */
132
    public function roles()
133
    {
134
        if ($this->roles) return $this->roles;
135
136
        $this->roles = new RoleHandler;
137
        return $this->roles();
138
    }
139
140
    /**
141
     * Learning Locker API: Role
142
     *
143
     * @param $id
144
     * @return RoleHandler
145
     */
146
    public function role($id = null)
147
    {
148
        if ($this->role) return $this->role;
149
150
        $this->role = new RoleHandler($id ? $id : null);
151
        return $this->role($id ? $id : null);
152
    }
153
154
    /**
155
     * Learning Locker API: Stores (LRS)
156
     *
157
     * @return StoreHandler
158
     */
159
    public function stores()
160
    {
161
        if ($this->stores) return $this->stores;
162
163
        $this->stores = new StoreHandler;
164
        return $this->stores();
165
    }
166
167
    /**
168
     * Learning Locker API: Store (LRS)
169
     *
170
     * @param $id
171
     * @return StoreHandler
172
     */
173
    public function store($id = null)
174
    {
175
        if ($this->store) return $this->store;
176
177
        $this->store = new StoreHandler($id ? $id : null);
178
        return $this->store($id ? $id : null);
179
    }
180
181
    /**
182
     * Learning Locker API: Query
183
     *
184
     * @return QueryHandler
185
     */
186
    public function queries()
187
    {
188
        if ($this->queries) return $this->queries;
189
190
        $this->queries = new QueryHandler;
191
        return $this->queries();
192
    }
193
194
    /**
195
     * Learning Locker API: Query
196
     *
197
     * @return QueryHandler
198
     */
199
    public function query($id = null)
200
    {
201
        if ($this->query) return $this->query;
202
203
        $this->query = new QueryHandler($id ? $id : null);
204
        return $this->query($id ? $id : null);
205
    }
206
207
    /**
208
     * Learning Locker API: Exports
209
     *
210
     * @return ExportHandler
211
     */
212
    public function exports()
213
    {
214
        if ($this->exports) return $this->exports;
215
216
        $this->exports = new ExportHandler;
217
        return $this->exports();
218
    }
219
220
    /**
221
     * Learning Locker API: Exports
222
     *
223
     * @return ExportHandler
224
     */
225
    public function export($id = null)
226
    {
227
        if ($this->export) return $this->export;
228
229
        $this->export = new ExportHandler($id ? $id : null);
230
        return $this->export($id ? $id : null);
231
    }
232
233
    /**
234
     * Learning Locker API: Personas
235
     *
236
     * @return PersonaHandler
237
     */
238
    public function personas()
239
    {
240
        if ($this->personas) return $this->personas;
241
242
        $this->personas = new PersonaHandler;
243
        return $this->personas();
244
    }
245
246
    /**
247
     * Learning Locker API: Persona
248
     *
249
     * @param $id
250
     * @return PersonaHandler
251
     */
252
    public function persona($id = null)
253
    {
254
        if ($this->persona) return $this->persona;
255
256
        $this->persona = new PersonaHandler($id ? $id : null);
257
        return $this->persona($id ? $id : null);
258
    }
259
260
    /**
261
     * Learning Locker API: Journeys
262
     *
263
     * @return JourneyHandler
264
     */
265
    public function journeys()
266
    {
267
        if ($this->journeys) return $this->journeys;
268
269
        $this->journeys = new JourneyHandler;
270
        return $this->journeys();
271
    }
272
273
    /**
274
     * Learning Locker API: Journey
275
     *
276
     * @param $id
277
     * @return JourneyHandler
278
     */
279
    public function journey($id = null)
280
    {
281
        if ($this->journey) return $this->journey;
282
283
        $this->journey = new JourneyHandler($id ? $id : null);
284
        return $this->journey($id ? $id : null);
285
    }
286
287
    /**
288
     * Learning Locker API: Journey
289
     *
290
     * @param $id
291
     * @return JourneyHandler
292
     */
293
    public function journeyProgress($id = null)
294
    {
295
        if ($this->journey_progress) return $this->journey_progress;
296
297
        $this->journey_progress = new JourneyProgressHandler($id ? $id : null);
298
        return $this->journeyProgress($id ? $id : null);
299
    }
300
301
    /**
302
     * Learning Locker API: Dashboards API
303
     *
304
     * @return DashboardHandler
305
     */
306
    public function dashboards()
307
    {
308
        if ($this->dashboards) return $this->dashboards;
309
310
        $this->dashboards = new DashboardHandler;
311
        return $this->dashboards();
312
    }
313
314
    /**
315
     * Learning Locker API: Dashboards API
316
     *
317
     * @param $id
318
     * @return DashboardHandler
319
     */
320
    public function dashboard($id = null)
321
    {
322
        if ($this->dashboard) return $this->dashboard;
323
324
        $this->dashboard = new DashboardHandler($id ? $id : null);
325
        return $this->dashboard($id ? $id : null);
326
    }
327
328
    /**
329
     * Learning Locker API: Downloads
330
     *
331
     * @return DownloadsHandler
0 ignored issues
show
Bug introduced by ijeffro
The type Ijeffro\Laralocker\DownloadsHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
332
     */
333
    public function downloads()
334
    {
335
        if ($this->downloads) return $this->downloads;
336
337
        $this->downloads = new DownloadHandler;
338
        return $this->downloads();
339
    }
340
341
    /**
342
     * Learning Locker API: Downloads
343
     *
344
     * @return DownloadsHandler
345
     */
346
    public function download($id)
347
    {
348
        if ($this->download) return $this->download;
349
350
        $this->download = new DownloadHandler($id);
351
        return $this->download($id);
352
    }
353
354
    /**
355
     * Learning Locker API: Statements
356
     *
357
     * @return StatementHandler
358
     */
359
    public function statements()
360
    {
361
        if ($this->statements) return $this->statements;
362
363
        $this->statements = new StatementHandler;
364
        return $this->statements();
365
    }
366
367
    /**
368
     * Learning Locker API: Statement
369
     *
370
     * @param $id
371
     * @return StatementHandler
372
     */
373
    public function statement($id = null)
374
    {
375
        if ($this->statement) return $this->statement;
376
377
        $this->statement = new StatementHandler($id ?? $id);
378
        return $this->statement($id ?? $id);
379
    }
380
381
    /**
382
     * Learning Locker API: Statements
383
     *
384
     * @return StatementHandler
385
     */
386
    public function statementForwarding($id = null)
387
    {
388
        if ($this->statement_forwarding) return $this->statement_forwarding;
389
390
        $this->statement_forwarding = new StatementForwardingHandler($id ?? $id);
391
        return $this->statementForwarding($id ?? $id);
392
    }
393
394
    /**
395
     * Learning Locker API: Organisation
396
     *
397
     * @param $id
398
     * @return OrganisationHandler
399
     */
400
    public function organisation($id)
401
    {
402
        if ($this->organisation) return $this->organisation;
403
404
        $this->organisation = new OrganisationHandler($id);
405
        return $this->organisation($id);
406
407
    }
408
409
    /**
410
     * Learning Locker API: Visualisations API
411
     *
412
     * @return VisualisationHandler
413
     */
414
    public function visualisations()
415
    {
416
        if ($this->visualisations) return $this->visualisations;
417
418
        $this->visualisations = new VisualisationHandler;
419
        return $this->visualisations();
420
    }
421
422
    /**
423
     * Learning Locker API: Visualisations API
424
     *
425
     * @param integer|null $id
426
     * @return VisualisationHandler
427
     */
428
    public function visualisation($id = null)
429
    {
430
        if ($this->visualisation) return $this->visualisation;
431
432
        $this->visualisation = new VisualisationHandler($id ? $id : null);
433
        return $this->visualisation($id ? $id : null);
434
    }
435
436
    /**
437
     * Learning Locker API: Routes
438
     *
439
     */
440
    public function routes()
441
    {
442
        require __DIR__.'/../routes/laralocker.php';
443
    }
444
445
    /**
446
     * Learning Locker API: Model Access
447
     *
448
     * @param $model, $id = null
0 ignored issues
show
Documentation Bug introduced by ijeffro
The doc comment $model, at position 0 could not be parsed: Unknown type name '$model' at position 0 in $model,.
Loading history...
449
     */
450
    public function api($model, $id = null) {
451
452
        switch (strtolower($model)) {
453
            case "clients":
454
                $this->clients();
455
                break;
456
            case "client":
457
                $this->client($id);
458
                break;
459
            case "user" || "users":
460
                $this->users();
461
                break;
462
            case "stores" || "store" || "lrs":
463
                $this->stores();
464
                break;
465
            case "query" || "queries":
466
                $this->query();
467
                break;
468
            case "export" || "exports":
469
                $this->exports();
470
                break;
471
            case "export" || "exports":
472
                $this->personas();
473
                break;
474
            case "journey" || "journeys":
475
                $this->journeys();
476
                break;
477
            case "dashboard" || "dashboards":
478
                $this->dashboards();
479
                break;
480
            case "download" || "downloads":
481
                $this->downloads();
482
                break;
483
            case "statement" || "statements":
484
                $this->statements();
485
                break;
486
            case "organisation" || "organisations" || "org":
487
                $this->organisations();
0 ignored issues
show
Bug introduced by ijeffro
The method organisations() does not exist on Ijeffro\Laralocker\LearningLocker. Did you maybe mean organisation()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

487
                $this->/** @scrutinizer ignore-call */ 
488
                       organisations();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
488
                break;
489
            case "visualisation" || "visualisations" || "visualise":
490
                $this->visualisations();
491
                break;
492
            default:
493
494
            $message = ["error" => "Please supply a Learning Locker model", "docs" => "http://docs.learninglocker.net/"];
495
496
            return $message->toJosn();
497
        }
498
    }
499
500
}
501