DashboardHandler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 33
c 1
b 0
f 0
dl 0
loc 77
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 7 2
A get() 0 7 2
A update() 0 7 2
A delete() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
namespace Ijeffro\Laralocker\LearningLocker\Dashboards;
4
5
use Ijeffro\Laralocker\LearningLocker\API\APIHandler;
6
7
class DashboardHandler extends APIHandler implements DashboardInterface {
8
9
10
    private $dashboard = '/dashboard';
11
    private $api = '/api';
12
    private $v1 = '/v1';
0 ignored issues
show
introduced by
The private property $v1 is not used, and could be removed.
Loading history...
13
    private $v2 = '/v2';
14
15
    protected $headers = [
16
      'Content-Type' => 'application/json'
17
    ];
18
19
    public function __construct($id = null) {
20
        parent::__construct();
21
        $this->id = $id;
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
    }
23
24
    /**
25
     * Learning Locker API: Get Dashboard
26
     *
27
     * @return  $response
0 ignored issues
show
Documentation Bug introduced by
The doc comment $response at position 0 could not be parsed: Unknown type name '$response' at position 0 in $response.
Loading history...
28
     */
29
    public function get() {
30
        try {
31
            $url = $this->url . $this->api . $this->v2 . $this->dashboard;
32
            $response = $this->request($url);
33
            return $response;
34
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The type Ijeffro\Laralocker\Learn...er\Dashboards\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
35
            return $e;
36
        }
37
    }
38
39
    /**
40
     * Learning Locker API: Update Dashboard
41
     *
42
     * @param  $data
43
     * @return $response
0 ignored issues
show
Documentation Bug introduced by
The doc comment $response at position 0 could not be parsed: Unknown type name '$response' at position 0 in $response.
Loading history...
44
     */
45
    public function update($data) {
46
        try {
47
            $url = $this->url . $this->api . $this->v2 . $this->dashboard . '/' . $this->id ?? $this->id;
48
            $response = $this->save($url, $data);
49
            return $response;
50
        } catch (Exception $e) {
51
            return $e;
52
        }
53
    }
54
55
56
    /**
57
     * Learning Locker: Request Organisation Details
58
     *
59
     * @return  $response
0 ignored issues
show
Documentation Bug introduced by
The doc comment $response at position 0 could not be parsed: Unknown type name '$response' at position 0 in $response.
Loading history...
60
     */
61
    public function delete() {
62
        try {
63
            $url = $this->url . $this->api . $this->v2 . $this->dashboard . '/' . $this->id;
64
            $response = $this->destroy($url);
65
            return $response;
66
        } catch (Exception $e) {
67
            return $e;
68
        }
69
    }
70
71
    /**
72
     * Learning Locker API: Create Dashboard
73
     *
74
     * @param  $data
75
     * @return $response
0 ignored issues
show
Documentation Bug introduced by
The doc comment $response at position 0 could not be parsed: Unknown type name '$response' at position 0 in $response.
Loading history...
76
     */
77
    public function create($data = null) {
78
        try {
79
            $url = $this->url . $this->api . $this->v2 . $this->dashboard;
80
            $response = $this->make($url, $data);
81
            return $response;
82
        } catch (Exception $e) {
83
            return $e;
84
        }
85
    }
86
}
87