Passed
Push — master ( 750b93...4c50c2 )
by Stephen
13:24
created

Acme::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
require __DIR__ . '/../vendor/autoload.php';
4
5
use Suitcase\Builder\SDK;
6
7
class Acme
8
{
9
    protected $client;
10
11
    protected $resource = '';
12
13
    private function __construct(string $authToken)
14
    {
15
        $this->client = SDK::make('https://api.acme.com')->withAuthHeaders($authToken);
16
    }
17
18
    public static function create(string $authToken): self
19
    {
20
        return new self($authToken);
21
    }
22
23
    public function load(...$resources): self
24
    {
25
        foreach ($resources as $resource) {
26
            $this->client->add($resource);
27
        }
28
29
        return $this;
30
    }
31
32
    public function __get(string $resource): self
33
    {
34
        $this->resource = $resource;
35
36
        return $this;
37
    }
38
39
    public function get(): array
40
    {
41
        return json_decode($this->client->use($this->resource)->get()->getBody()->getContents());
42
    }
43
44
    public function find($identifier)
45
    {
46
        return json_decode($this->client->use($this->resource)->find($identifier)->getBody()->getContents());
47
    }
48
}
49
50
// Create your SDK
51
$acme = Acme::create('1234-api-token-1234')->load('users', 'posts'. 'categories', 'likes');
52
53
// Access the Users resource and get all records from your API
54
$acme->users->get();
0 ignored issues
show
Bug Best Practice introduced by
The property users does not exist on Acme. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
56
// Access the Users resource and find a specific resource using an identifier from your API
57
$acme->users->find(1);
58
59
60
61
62
63
64
65
66
67