Completed
Push — master ( 460c84...4424bf )
by Jeroen
04:37
created

ShopsUnitedLaravel::accounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace JeroenBoesten\ShopsUnitedLaravel;
4
5
use GuzzleHttp\Client;
6
use JeroenBoesten\ShopsUnitedLaravel\Modules\Accounts;
7
use JeroenBoesten\ShopsUnitedLaravel\Modules\Shipments;
8
9
class ShopsUnitedLaravel
10
{
11
    protected $url;
12
    protected $query;
13
    protected $callableUrl;
14
    protected $method = 'GET';
15
    protected $params = [];
16
17
    public function __construct()
18
    {
19
        $this->client = new Client(['verify' => config('shops-united-laravel.verify-ssl')]);
0 ignored issues
show
Bug introduced by
The property client 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...
20
21
        $this->baseUrl = 'https://login.shops-united.nl/api/';
0 ignored issues
show
Bug introduced by
The property baseUrl 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...
22
    }
23
24
    public function accounts()
25
    {
26
        return new Accounts();
27
    }
28
29
    public function shipments()
30
    {
31
        return new Shipments();
32
    }
33
34
    protected function call()
35
    {
36
        $request = $this->client->request($this->method, $this->callableUrl.$this->query, [
37
            'form_params' => $this->params,
38
        ]);
39
40
        return json_decode($request
41
            ->getBody()
42
            ->getContents(), true);
43
    }
44
45
    protected function setGetUrl($url = null)
46
    {
47
        $this->method = 'GET';
48
        $this->callableUrl = $this->baseUrl.$url;
49
50
        return $this;
51
    }
52
53
    public function setPostUrl($url)
54
    {
55
        $this->method = 'POST';
56
        $this->callableUrl = $this->baseUrl.$url;
57
58
        return $this;
59
    }
60
61
    public function setDeleteUrl($url)
62
    {
63
        $this->method = 'DELETE';
64
        $this->callableUrl = $this->baseUrl.$url;
65
66
        return $this;
67
    }
68
69
    protected function addQuery(array $array)
70
    {
71
        $this->query = '?'.http_build_query($array);
72
73
        return $this;
74
    }
75
76
    protected function setParams(array $array)
77
    {
78
        $this->params = $array;
79
80
        return $this;
81
    }
82
}
83