API   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 66
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A access() 0 3 1
A get() 0 4 1
A create() 0 3 1
A update() 0 4 1
A delete() 0 3 1
1
<?php
2
3
namespace FLAIRUK\GoodTillSystem;
4
5
use Illuminate\Support\Facades\Http;
6
use FLAIRUK\GoodTillSystem\Authorize;
7
use Illuminate\Support\Facades\Config;
8
use FLAIRUK\GoodTillSystem\RESTInterface;
9
use Illuminate\Http\Client\PendingRequest;
10
11
class API implements RESTInterface {
12
13
    protected $url;
14
    protected $payload;
15
16
    /**
17
     * Create a new GoodTill instance.
18
     *
19
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
20
     */
21
    public function __construct($user, $url, $id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

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

Loading history...
22
    {
23
        $this->url = $url;
24
        $this->user = $user;
0 ignored issues
show
Bug introduced by
The property user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    /**
28
     * Good Till API: Access
29
     * 
30
     * @return PendingRequest
31
     */
32
    public function access(): PendingRequest {
33
        return Http::withToken($this->user['token']);
34
    }
35
36
    /**
37
     * Good Till API: Get Outlet Model
38
     * 
39
     * @return array
40
     */
41
    public function get(): array {
42
        // dump($this->url, $this->user['token']); die;
43
        return $this->access()->get($this->url)->json();
44
    }
45
46
    /**
47
     * Good Till API: Create
48
     * 
49
     * @param array $data
50
     * @return array
51
     */
52
    public function create(array $data = []): array {
53
        return $this->access()->post($this->url, $data)->json();
54
    }
55
56
    /**
57
     * Good Till API: Update
58
     * 
59
     * @param array $data
60
     * @return array
61
     */
62
    public function update(array $data): array {
63
        // dump($this->url, $this->user['token']); die;
64
        return $this->access()->patch($this->url, $data)->json();
65
    }
66
67
    /**
68
     * Good Till API: Delete
69
     * 
70
     * @param array $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
71
     * @return array
72
     */
73
    public function delete(): array {
74
        return $this->access()->post($this->url . 'delete/' . $this->id)->json();
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
75
    }
76
}
77