StoreHandler   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 35
c 1
b 0
f 0
dl 0
loc 79
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 7 2
A __construct() 0 4 2
A create() 0 7 2
A update() 0 7 2
A get() 0 11 3
1
<?php
2
3
namespace Ijeffro\Laralocker\LearningLocker\Stores;
4
5
use Ijeffro\Laralocker\LearningLocker\API\APIHandler;
6
7
class StoreHandler extends APIHandler {
8
9
    private $store = '/lrs';
10
    private $api = '/api';
11
    private $v1 = '/v1';
0 ignored issues
show
introduced by
The private property $v1 is not used, and could be removed.
Loading history...
12
    private $v2 = '/v2';
13
14
    protected $headers = [
15
        'Accept' => 'application/json',
16
        'Content-Type' => 'application/json'
17
    ];
18
19
    public function __construct($id = null) {
20
        parent::__construct();
21
22
        $this->id = $id ? $id : null;
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...
23
    }
24
25
    /**
26
     * Learning Locker: Request Organisation Details
27
     *
28
     * @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...
29
     */
30
    public function get($selected = []) {
31
        try {
32
            $url = $this->url . $this->api . $this->v2 . $this->store . '/' . $this->id ?? $this->id;
33
            $response = $this->request($url);
34
35
            if ($selected) $response = $this->select($selected, $response);
36
37
            return $response;
38
39
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The type Ijeffro\Laralocker\LearningLocker\Stores\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
40
            return $e;
41
        }
42
    }
43
44
    /**
45
     * Learning Locker: Update Store
46
     *
47
     * @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...
48
     */
49
    public function update($data) {
50
        try {
51
            $url = $this->url . $this->api . $this->v2 . $this->store . '/' . $this->id;
52
            $response = $this->save($url, $data);
53
            return $response;
54
        } catch (Exception $e) {
55
            return $e;
56
        }
57
    }
58
59
    /**
60
     * Learning Locker: Request Organisation Details
61
     *
62
     * @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...
63
     */
64
    public function delete() {
65
        try {
66
            $url = $this->url . $this->api . $this->v2 . $this->store . '/' . $this->id;
67
            $response = $this->destroy($url);
68
            return $response;
69
        } catch (Exception $e) {
70
            return $e;
71
        }
72
    }
73
74
    /**
75
     * Learning Locker: Request Organisation Details
76
     *
77
     * @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...
78
     */
79
    public function create($data = null) {
80
        try {
81
            $url = $this->url . $this->api . $this->v2 . $this->store;
82
            $response = $this->make($url, $data);
83
            return $response;
84
        } catch (Exception $e) {
85
            return $e;
86
        }
87
    }
88
}
89