QueryHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 21
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A update() 0 7 2
A get() 0 7 2
1
<?php
2
3
namespace Ijeffro\Laralocker\LearningLocker\Queries;
4
5
use Ijeffro\Laralocker\LearningLocker\API\APIHandler;
6
7
class QueryHandler extends APIHandler implements QueryInterface {
8
9
    private $query = '/query';
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
      'content-type' => 'application/json'
16
    ];
17
18
    function __construct($id = null) {
19
        parent::__construct();
20
        $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...
21
    }
22
23
    /**
24
     * Learning Locker: Request Organisation Details
25
     *
26
     * @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...
27
     */
28
    public function get() {
29
        try {
30
            $url = $this->url . $this->api . $this->v2 . $this->query . '/' . $this->id ?? $this->id;
31
            $response = $this->request($url);
32
            return $response;
33
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The type Ijeffro\Laralocker\Learn...ocker\Queries\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
34
            return $e;
35
        }
36
    }
37
38
    /**
39
     * Learning Locker: Request Organisation Details
40
     *
41
     * @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...
42
     */
43
    public function update($data) {
44
        try {
45
            $url = $this->url . $this->api . $this->v2 . $this->query . '/' . $this->id ?? $this->id;
46
            $response = $this->save($url, $data);
47
            return $response;
48
        } catch (Exception $e) {
49
            return $e;
50
        }
51
    }
52
}
53