Issues (256)

src/LearningLocker/Client/ClientHandler.php (7 issues)

1
<?php
2
3
namespace Ijeffro\Laralocker\LearningLocker\Client;
4
5
6
use Ijeffro\Laralocker\LearningLocker\API\APIHandler;
7
8
class ClientHandler extends APIHandler {
9
10
    private $client = '/client';
11
    private $api = '/api';
12
    private $v1 = '/v1';
0 ignored issues
show
The private property $v1 is not used, and could be removed.
Loading history...
13
    private $v2 = '/v2';
14
15
    protected $headers = [
16
        'Accept' => 'application/json',
17
        'Content-Type' => 'application/json'
18
    ];
19
20
21
    function __construct($id = null) {
22
        parent::__construct();
23
        $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...
24
    }
25
26
    /**
27
     * Learning Locker: Request Organisation Details
28
     *
29
     * @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...
30
     */
31
    public function get($selected = []) {
32
        try {
33
            $url = $this->url . $this->api . $this->v2 . $this->client . '/' . $this->id ??  $this->id;
34
            $response = $this->request($url);
35
36
            if ($selected) $response = $this->select($selected, $response);
37
38
            return $response;
39
        } catch (Exception $e) {
0 ignored issues
show
The type Ijeffro\Laralocker\LearningLocker\Client\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: Request Organisation Details
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->client . '/' . $this->id ?? $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->client . '/' . $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->client;
82
            $response = $this->make($url, $data);
83
            return $response;
84
        } catch (Exception $e) {
85
            return $e;
86
        }
87
    }
88
89
}
90